Skip to content

Commit 83310f6

Browse files
committed
type Distribution.get_command_obj to not return None with create=True
1 parent 2517976 commit 83310f6

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

distutils/dist.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
Provides the Distribution class, which represents the module distribution
44
being built/installed/distributed.
55
"""
6+
from __future__ import annotations
67

78
import contextlib
89
import logging
910
import os
1011
import pathlib
1112
import re
1213
import sys
14+
from typing import TYPE_CHECKING, Literal, overload
1315
import warnings
1416
from collections.abc import Iterable
1517
from email import message_from_file
@@ -27,6 +29,10 @@
2729
from .fancy_getopt import FancyGetopt, translate_longopt
2830
from .util import check_environ, rfc822_escape, strtobool
2931

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

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

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

0 commit comments

Comments
 (0)