Skip to content

Commit f5b6dc2

Browse files
committed
type Distribution.get_command_obj to not return None with create=True
1 parent a9f832b commit f5b6dc2

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

distutils/dist.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
being built/installed/distributed.
55
"""
66

7+
from __future__ import annotations
8+
79
import contextlib
810
import logging
911
import os
@@ -13,6 +15,7 @@
1315
import warnings
1416
from collections.abc import Iterable
1517
from email import message_from_file
18+
from typing import TYPE_CHECKING, Literal, overload
1619

1720
from packaging.utils import canonicalize_name, canonicalize_version
1821

@@ -27,6 +30,10 @@
2730
from .fancy_getopt import FancyGetopt, translate_longopt
2831
from .util import check_environ, rfc822_escape, strtobool
2932

33+
if TYPE_CHECKING:
34+
# type-only import because of mutual dependence between these modules
35+
from .cmd import Command
36+
3037
# Regex to define acceptable Distutils command names. This is not *quite*
3138
# the same as a Python NAME -- I don't allow leading underscores. The fact
3239
# that they're very similar is no coincidence; the default naming scheme is
@@ -829,7 +836,15 @@ def get_command_class(self, command):
829836

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

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

0 commit comments

Comments
 (0)