Skip to content

Commit 3e0269b

Browse files
authored
distutils & setuptools: Complete sub_commands ClassVar typing (#11951)
1 parent 36afde9 commit 3e0269b

File tree

8 files changed

+27
-17
lines changed

8 files changed

+27
-17
lines changed

stdlib/distutils/cmd.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ from _typeshed import Incomplete, Unused
22
from abc import abstractmethod
33
from collections.abc import Callable, Iterable
44
from distutils.dist import Distribution
5-
from typing import Any, Literal
5+
from typing import Any, ClassVar, Literal
66

77
class Command:
88
distribution: Distribution
9-
sub_commands: list[tuple[str, Callable[[Command], bool] | None]]
9+
# Any to work around variance issues
10+
sub_commands: ClassVar[list[tuple[str, Callable[[Any], bool] | None]]]
1011
def __init__(self, dist: Distribution) -> None: ...
1112
@abstractmethod
1213
def initialize_options(self) -> None: ...

stdlib/distutils/command/build.pyi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from typing import Any
1+
from collections.abc import Callable
2+
from typing import Any, ClassVar
23

34
from ..cmd import Command
45

@@ -28,4 +29,5 @@ class build(Command):
2829
def has_c_libraries(self): ...
2930
def has_ext_modules(self): ...
3031
def has_scripts(self): ...
31-
sub_commands: Any
32+
# Any to work around variance issues
33+
sub_commands: ClassVar[list[tuple[str, Callable[[Any], bool] | None]]]

stdlib/distutils/command/install.pyi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from typing import Any
1+
from collections.abc import Callable
2+
from typing import Any, ClassVar
23

34
from ..cmd import Command
45

@@ -60,4 +61,5 @@ class install(Command):
6061
def has_headers(self): ...
6162
def has_scripts(self): ...
6263
def has_data(self): ...
63-
sub_commands: Any
64+
# Any to work around variance issues
65+
sub_commands: ClassVar[list[tuple[str, Callable[[Any], bool] | None]]]

stdlib/distutils/command/register.pyi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
from typing import Any
1+
from collections.abc import Callable
2+
from typing import Any, ClassVar
23

34
from ..config import PyPIRCCommand
45

56
class register(PyPIRCCommand):
67
description: str
7-
sub_commands: Any
8+
# Any to work around variance issues
9+
sub_commands: ClassVar[list[tuple[str, Callable[[Any], bool] | None]]]
810
list_classifiers: int
911
strict: int
1012
def initialize_options(self) -> None: ...

stdlib/distutils/command/sdist.pyi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from typing import Any
1+
from collections.abc import Callable
2+
from typing import Any, ClassVar
23

34
from ..cmd import Command
45

@@ -11,7 +12,8 @@ class sdist(Command):
1112
boolean_options: Any
1213
help_options: Any
1314
negative_opt: Any
14-
sub_commands: Any
15+
# Any to work around variance issues
16+
sub_commands: ClassVar[list[tuple[str, Callable[[Any], bool] | None]]]
1517
READMES: Any
1618
template: Any
1719
manifest: Any

stubs/setuptools/setuptools/_distutils/cmd.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
from _typeshed import Incomplete, Unused
22
from abc import abstractmethod
33
from collections.abc import Callable, Iterable
4-
from typing import ClassVar, Literal
5-
from typing_extensions import Self
4+
from typing import Any, ClassVar, Literal
65

76
from .dist import Distribution
87

98
class Command:
109
distribution: Distribution
11-
sub_commands: ClassVar[list[tuple[str, Callable[[Self], bool] | None]]]
10+
# Any to work around variance issues
11+
sub_commands: ClassVar[list[tuple[str, Callable[[Any], bool] | None]]]
1212
def __init__(self, dist: Distribution) -> None: ...
1313
def ensure_finalized(self) -> None: ...
1414
@abstractmethod

stubs/setuptools/setuptools/command/install.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
from collections.abc import Callable
12
from typing import Any
23

34
from .._distutils.command import install as orig
45

56
class install(orig.install):
67
user_options: Any
78
boolean_options: Any
8-
new_commands: Any
9+
# Any to work around variance issues
10+
new_commands: list[tuple[str, Callable[[Any], bool]] | None]
911
old_and_unmanageable: Any
1012
single_version_externally_managed: Any
1113
def initialize_options(self) -> None: ...

stubs/setuptools/setuptools/command/upload_docs.pyi

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from collections.abc import Callable
22
from typing import Any, ClassVar
3-
from typing_extensions import Self
43

54
from .upload import upload
65

@@ -10,8 +9,8 @@ class upload_docs(upload):
109
user_options: ClassVar[list[tuple[str, str | None, str]]]
1110
boolean_options: ClassVar[list[str]]
1211
def has_sphinx(self): ...
13-
# The callable parameter is self: Self, but using Self still trips up mypy
14-
sub_commands: ClassVar[list[tuple[str, Callable[[Self], bool] | None]]] # type: ignore[assignment]
12+
# Any to work around variance issues
13+
sub_commands: ClassVar[list[tuple[str, Callable[[Any], bool] | None]]]
1514
upload_dir: Any
1615
target_dir: Any
1716
def initialize_options(self) -> None: ...

0 commit comments

Comments
 (0)