Skip to content

Commit a8eec20

Browse files
authored
Merge pull request #319 from Avasam/classvar-mutables-and-tuple
Type ClassVar mutables and tuple from typeshed
2 parents cfc8c4a + 9d9887d commit a8eec20

10 files changed

+32
-15
lines changed

distutils/cmd.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
import os
1111
import re
1212
import sys
13-
from typing import TypeVar, overload
13+
from collections.abc import Callable
14+
from typing import Any, ClassVar, TypeVar, overload
1415

1516
from . import _modified, archive_util, dir_util, file_util, util
1617
from ._log import log
@@ -49,7 +50,14 @@ class Command:
4950
# 'sub_commands' is usually defined at the *end* of a class, because
5051
# predicates can be unbound methods, so they must already have been
5152
# defined. The canonical example is the "install" command.
52-
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+
] = []
5361

5462
# -- Creation/initialization methods -------------------------------
5563

distutils/command/bdist.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import os
77
import warnings
8+
from typing import ClassVar
89

910
from ..core import Command
1011
from ..errors import DistutilsOptionError, DistutilsPlatformError
@@ -23,7 +24,7 @@ def show_formats():
2324
pretty_printer.print_help("List of available distribution formats:")
2425

2526

26-
class ListCompat(dict):
27+
class ListCompat(dict[str, tuple[str, str]]):
2728
# adapter to allow for Setuptools compatibility in format_commands
2829
def append(self, item):
2930
warnings.warn(
@@ -70,7 +71,7 @@ class bdist(Command):
7071
]
7172

7273
# The following commands do not take a format option from bdist
73-
no_format_option = ('bdist_rpm',)
74+
no_format_option: ClassVar[tuple[str, ...]] = ('bdist_rpm',)
7475

7576
# This won't do in reality: will need to distinguish RPM-ish Linux,
7677
# Debian-ish Linux, Solaris, FreeBSD, ..., Windows, Mac OS.

distutils/command/build_clib.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import os
1818
from distutils._log import log
19+
from typing import ClassVar
1920

2021
from ..core import Command
2122
from ..errors import DistutilsSetupError
@@ -31,7 +32,7 @@ def show_compilers():
3132
class build_clib(Command):
3233
description = "build C/C++ libraries used by Python extensions"
3334

34-
user_options = [
35+
user_options: ClassVar[list[tuple[str, str, str]]] = [
3536
('build-clib=', 'b', "directory to build C/C++ libraries to"),
3637
('build-temp=', 't', "directory to put temporary build by-products"),
3738
('debug', 'g', "compile with debugging information"),

distutils/command/build_scripts.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from distutils import sysconfig
99
from distutils._log import log
1010
from stat import ST_MODE
11+
from typing import ClassVar
1112

1213
from .._modified import newer
1314
from ..core import Command
@@ -25,7 +26,7 @@
2526
class build_scripts(Command):
2627
description = "\"build\" scripts (copy and fixup #! line)"
2728

28-
user_options = [
29+
user_options: ClassVar[list[tuple[str, str, str]]] = [
2930
('build-dir=', 'd', "directory to \"build\" (copy) to"),
3031
('force', 'f', "forcibly build everything (ignore file timestamps"),
3132
('executable=', 'e', "specify final destination interpreter path"),

distutils/command/check.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55

66
import contextlib
7+
from typing import ClassVar
78

89
from ..core import Command
910
from ..errors import DistutilsSetupError
@@ -41,7 +42,7 @@ class check(Command):
4142
"""This command checks the meta-data of the package."""
4243

4344
description = "perform some checks on the package"
44-
user_options = [
45+
user_options: ClassVar[list[tuple[str, str, str]]] = [
4546
('metadata', 'm', 'Verify meta-data'),
4647
(
4748
'restructuredtext',

distutils/command/command_template

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ Implements the Distutils 'x' command.
88
__revision__ = "$Id$"
99

1010
from distutils.core import Command
11+
from typing import ClassVar
1112

1213

1314
class x(Command):
14-
1515
# Brief (40-50 characters) description of the command
1616
description = ""
1717

1818
# List of option tuples: long name, short name (None if no short
1919
# name), and help string.
20-
user_options = [('', '',
21-
""),
22-
]
20+
user_options: ClassVar[list[tuple[str, str, str]]] = [
21+
('', '', ""),
22+
]
2323

2424
def initialize_options(self):
2525
self. = None

distutils/command/install_egg_info.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import os
99
import re
1010
import sys
11+
from typing import ClassVar
1112

1213
from .. import dir_util
1314
from .._log import log
@@ -18,7 +19,7 @@ class install_egg_info(Command):
1819
"""Install an .egg-info file for the package"""
1920

2021
description = "Install package's PKG-INFO metadata as an .egg-info file"
21-
user_options = [
22+
user_options: ClassVar[list[tuple[str, str, str]]] = [
2223
('install-dir=', 'd', "directory to install to"),
2324
]
2425

distutils/command/install_headers.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
Implements the Distutils 'install_headers' command, to install C/C++ header
44
files to the Python include directory."""
55

6+
from typing import ClassVar
7+
68
from ..core import Command
79

810

911
# XXX force is never used
1012
class install_headers(Command):
1113
description = "install C/C++ header files"
1214

13-
user_options = [
15+
user_options: ClassVar[list[tuple[str, str, str]]] = [
1416
('install-dir=', 'd', "directory to install header files to"),
1517
('force', 'f', "force installation (overwrite existing files)"),
1618
]

distutils/command/sdist.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from distutils._log import log
99
from glob import glob
1010
from itertools import filterfalse
11+
from typing import ClassVar
1112

1213
from ..core import Command
1314
from ..errors import DistutilsOptionError, DistutilsTemplateError
@@ -114,7 +115,7 @@ def checking_metadata(self):
114115

115116
sub_commands = [('check', checking_metadata)]
116117

117-
READMES = ('README', 'README.txt', 'README.rst')
118+
READMES: ClassVar[tuple[str, ...]] = ('README', 'README.txt', 'README.rst')
118119

119120
def initialize_options(self):
120121
# 'template' and 'manifest' are, respectively, the names of

distutils/tests/test_dist.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from distutils.cmd import Command
1414
from distutils.dist import Distribution, fix_help_options
1515
from distutils.tests import support
16+
from typing import ClassVar
1617

1718
import jaraco.path
1819
import pytest
@@ -23,7 +24,7 @@
2324
class test_dist(Command):
2425
"""Sample distutils extension command."""
2526

26-
user_options = [
27+
user_options: ClassVar[list[tuple[str, str, str]]] = [
2728
("sample-option=", "S", "help text"),
2829
]
2930

0 commit comments

Comments
 (0)