Skip to content

Commit cfc8c4a

Browse files
authored
Merge pull request #307 from Avasam/get_command_obj-overload
type `Distribution.get_command_obj` to not return `None` with `create=True`
2 parents cebba7f + deb1d5a commit cfc8c4a

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")
@@ -839,7 +840,15 @@ def get_command_class(self, command):
839840

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

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

0 commit comments

Comments
 (0)