|
4 | 4 | being built/installed/distributed.
|
5 | 5 | """
|
6 | 6 |
|
| 7 | +from __future__ import annotations |
| 8 | + |
7 | 9 | import contextlib
|
8 | 10 | import logging
|
9 | 11 | import os
|
|
13 | 15 | import warnings
|
14 | 16 | from collections.abc import Iterable
|
15 | 17 | from email import message_from_file
|
| 18 | +from typing import TYPE_CHECKING, Literal, overload |
16 | 19 |
|
17 | 20 | from packaging.utils import canonicalize_name, canonicalize_version
|
18 | 21 |
|
|
27 | 30 | from .fancy_getopt import FancyGetopt, translate_longopt
|
28 | 31 | from .util import check_environ, rfc822_escape, strtobool
|
29 | 32 |
|
| 33 | +if TYPE_CHECKING: |
| 34 | + # type-only import because of mutual dependence between these modules |
| 35 | + from .cmd import Command |
| 36 | + |
30 | 37 | # Regex to define acceptable Distutils command names. This is not *quite*
|
31 | 38 | # the same as a Python NAME -- I don't allow leading underscores. The fact
|
32 | 39 | # that they're very similar is no coincidence; the default naming scheme is
|
@@ -829,7 +836,15 @@ def get_command_class(self, command):
|
829 | 836 |
|
830 | 837 | raise DistutilsModuleError(f"invalid command '{command}'")
|
831 | 838 |
|
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: |
833 | 848 | """Return the command object for 'command'. Normally this object
|
834 | 849 | is cached on a previous call to 'get_command_obj()'; if no command
|
835 | 850 | object for 'command' is in the cache, then we either create and
|
|
0 commit comments