Skip to content

Commit deb1d5a

Browse files
committed
type Distribution.get_command_obj to not return None with create=True
1 parent 22b61d9 commit deb1d5a

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

distutils/dist.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import warnings
1616
from collections.abc import Iterable
1717
from email import message_from_file
18-
from typing import TYPE_CHECKING, TypeVar, overload
18+
from typing import TYPE_CHECKING, Literal, TypeVar, overload
1919

2020
from packaging.utils import canonicalize_name, canonicalize_version
2121

@@ -31,6 +31,7 @@
3131
from .util import check_environ, rfc822_escape, strtobool
3232

3333
if TYPE_CHECKING:
34+
# type-only import because of mutual dependence between these modules
3435
from .cmd import Command
3536

3637
_CommandT = TypeVar("_CommandT", bound="Command")
@@ -837,7 +838,15 @@ def get_command_class(self, command):
837838

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

840-
def get_command_obj(self, command, create=True):
841+
@overload
842+
def get_command_obj(
843+
self, command: str, create: Literal[True] = True
844+
) -> Command: ...
845+
@overload
846+
def get_command_obj(
847+
self, command: str, create: Literal[False]
848+
) -> Command | None: ...
849+
def get_command_obj(self, command: str, create: bool = True) -> Command | None:
841850
"""Return the command object for 'command'. Normally this object
842851
is cached on a previous call to 'get_command_obj()'; if no command
843852
object for 'command' is in the cache, then we either create and

0 commit comments

Comments
 (0)