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 Dec 27, 2024
1 parent 22b61d9 commit cef37dd
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions distutils/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import warnings
from collections.abc import Iterable
from email import message_from_file
from typing import TYPE_CHECKING, TypeVar, overload
from typing import TYPE_CHECKING, Literal, TypeVar, overload

from packaging.utils import canonicalize_name, canonicalize_version

Expand All @@ -31,10 +31,12 @@
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

_CommandT = TypeVar("_CommandT", bound="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 @@ -837,7 +839,15 @@ 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 cef37dd

Please sign in to comment.