Skip to content

Commit

Permalink
type Distribution.get_command_obj to not return None with `create…
Browse files Browse the repository at this point in the history
…=True`
  • Loading branch information
Avasam committed Oct 25, 2024
1 parent 5904204 commit 16433c1
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion distutils/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
Provides the Distribution class, which represents the module distribution
being built/installed/distributed.
"""
from __future__ import annotations

import contextlib
import logging
import os
import pathlib
import re
import sys
from typing import TYPE_CHECKING, Literal, overload
import warnings
from collections.abc import Iterable
from email import message_from_file
Expand All @@ -27,6 +29,10 @@
from .fancy_getopt import FancyGetopt, translate_longopt
from .util import check_environ, rfc822_escape, strtobool

if TYPE_CHECKING:
# type-only import because of mutual dependence between these modules
from .cmd import Command

# Regex to define acceptable Distutils command names. This is not *quite*
# the same as a Python NAME -- I don't allow leading underscores. The fact
# that they're very similar is no coincidence; the default naming scheme is
Expand Down Expand Up @@ -829,7 +835,11 @@ def get_command_class(self, command):

raise DistutilsModuleError(f"invalid command '{command}'")

def get_command_obj(self, command, create=True):
@overload
def get_command_obj(self, command: str, create: Literal[True] = True) -> Command: ...
@overload
def get_command_obj(self, command: str, create: Literal[False]) -> Command | None: ...
def get_command_obj(self, command: str, create: bool = True) -> Command | None:
"""Return the command object for 'command'. Normally this object
is cached on a previous call to 'get_command_obj()'; if no command
object for 'command' is in the cache, then we either create and
Expand Down

0 comments on commit 16433c1

Please sign in to comment.