|
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, TypeVar, 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 | + from .cmd import Command |
| 35 | + |
| 36 | +_CommandT = TypeVar("_CommandT", bound="Command") |
| 37 | + |
30 | 38 | # Regex to define acceptable Distutils command names. This is not *quite*
|
31 | 39 | # the same as a Python NAME -- I don't allow leading underscores. The fact
|
32 | 40 | # that they're very similar is no coincidence; the default naming scheme is
|
@@ -900,7 +908,17 @@ def _set_command_options(self, command_obj, option_dict=None): # noqa: C901
|
900 | 908 | except ValueError as msg:
|
901 | 909 | raise DistutilsOptionError(msg)
|
902 | 910 |
|
903 |
| - def reinitialize_command(self, command, reinit_subcommands=False): |
| 911 | + @overload |
| 912 | + def reinitialize_command( |
| 913 | + self, command: str, reinit_subcommands: bool = False |
| 914 | + ) -> Command: ... |
| 915 | + @overload |
| 916 | + def reinitialize_command( |
| 917 | + self, command: _CommandT, reinit_subcommands: bool = False |
| 918 | + ) -> _CommandT: ... |
| 919 | + def reinitialize_command( |
| 920 | + self, command: str | Command, reinit_subcommands=False |
| 921 | + ) -> Command: |
904 | 922 | """Reinitializes a command to the state it was in when first
|
905 | 923 | returned by 'get_command_obj()': ie., initialized but not yet
|
906 | 924 | finalized. This provides the opportunity to sneak option
|
|
0 commit comments