|
4 | 4 | in the distutils.command package.
|
5 | 5 | """
|
6 | 6 |
|
| 7 | +from __future__ import annotations |
| 8 | + |
7 | 9 | import logging
|
8 | 10 | import os
|
9 | 11 | import re
|
10 | 12 | import sys
|
| 13 | +from collections.abc import Callable |
| 14 | +from typing import Any, ClassVar, TypeVar, overload |
11 | 15 |
|
12 | 16 | from . import _modified, archive_util, dir_util, file_util, util
|
13 | 17 | from ._log import log
|
14 | 18 | from .errors import DistutilsOptionError
|
15 | 19 |
|
| 20 | +_CommandT = TypeVar("_CommandT", bound="Command") |
| 21 | + |
16 | 22 |
|
17 | 23 | class Command:
|
18 | 24 | """Abstract base class for defining command classes, the "worker bees"
|
@@ -44,7 +50,14 @@ class Command:
|
44 | 50 | # 'sub_commands' is usually defined at the *end* of a class, because
|
45 | 51 | # predicates can be unbound methods, so they must already have been
|
46 | 52 | # defined. The canonical example is the "install" command.
|
47 |
| - sub_commands = [] |
| 53 | + sub_commands: ClassVar[ # Any to work around variance issues |
| 54 | + list[tuple[str, Callable[[Any], bool] | None]] |
| 55 | + ] = [] |
| 56 | + |
| 57 | + user_options: ClassVar[ |
| 58 | + # Specifying both because list is invariant. Avoids mypy override assignment issues |
| 59 | + list[tuple[str, str, str]] | list[tuple[str, str | None, str]] |
| 60 | + ] = [] |
48 | 61 |
|
49 | 62 | # -- Creation/initialization methods -------------------------------
|
50 | 63 |
|
@@ -305,7 +318,17 @@ def get_finalized_command(self, command, create=True):
|
305 | 318 |
|
306 | 319 | # XXX rename to 'get_reinitialized_command()'? (should do the
|
307 | 320 | # same in dist.py, if so)
|
308 |
| - def reinitialize_command(self, command, reinit_subcommands=False): |
| 321 | + @overload |
| 322 | + def reinitialize_command( |
| 323 | + self, command: str, reinit_subcommands: bool = False |
| 324 | + ) -> Command: ... |
| 325 | + @overload |
| 326 | + def reinitialize_command( |
| 327 | + self, command: _CommandT, reinit_subcommands: bool = False |
| 328 | + ) -> _CommandT: ... |
| 329 | + def reinitialize_command( |
| 330 | + self, command: str | Command, reinit_subcommands=False |
| 331 | + ) -> Command: |
309 | 332 | return self.distribution.reinitialize_command(command, reinit_subcommands)
|
310 | 333 |
|
311 | 334 | def run_command(self, command):
|
|
0 commit comments