From d210abc96faffb79aac68c9100f5bec7353387dd Mon Sep 17 00:00:00 2001 From: Avasam Date: Fri, 17 May 2024 23:26:39 -0400 Subject: [PATCH 1/3] distutils: Complete sub_commands ClassVar typing --- stdlib/distutils/cmd.pyi | 5 +++-- stdlib/distutils/command/build.pyi | 6 ++++-- stdlib/distutils/command/install.pyi | 6 ++++-- stdlib/distutils/command/register.pyi | 6 ++++-- stdlib/distutils/command/sdist.pyi | 6 ++++-- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/stdlib/distutils/cmd.pyi b/stdlib/distutils/cmd.pyi index 94838ce2ca1a..0b4dee6ecafa 100644 --- a/stdlib/distutils/cmd.pyi +++ b/stdlib/distutils/cmd.pyi @@ -2,11 +2,12 @@ from _typeshed import Incomplete, Unused from abc import abstractmethod from collections.abc import Callable, Iterable from distutils.dist import Distribution -from typing import Any, Literal +from typing import Any, ClassVar, Literal +from typing_extensions import Self class Command: distribution: Distribution - sub_commands: list[tuple[str, Callable[[Command], bool] | None]] + sub_commands: ClassVar[list[tuple[str, Callable[[Self], bool] | None]]] def __init__(self, dist: Distribution) -> None: ... @abstractmethod def initialize_options(self) -> None: ... diff --git a/stdlib/distutils/command/build.pyi b/stdlib/distutils/command/build.pyi index cf3c8a562ff3..43400a8fb1f8 100644 --- a/stdlib/distutils/command/build.pyi +++ b/stdlib/distutils/command/build.pyi @@ -1,4 +1,6 @@ -from typing import Any +from collections.abc import Callable +from typing import Any, ClassVar +from typing_extensions import Self from ..cmd import Command @@ -28,4 +30,4 @@ class build(Command): def has_c_libraries(self): ... def has_ext_modules(self): ... def has_scripts(self): ... - sub_commands: Any + sub_commands: ClassVar[list[tuple[str, Callable[[Self], bool] | None]]] diff --git a/stdlib/distutils/command/install.pyi b/stdlib/distutils/command/install.pyi index 661d256e6f07..1f3c7514a1bc 100644 --- a/stdlib/distutils/command/install.pyi +++ b/stdlib/distutils/command/install.pyi @@ -1,4 +1,6 @@ -from typing import Any +from collections.abc import Callable +from typing import Any, ClassVar +from typing_extensions import Self from ..cmd import Command @@ -60,4 +62,4 @@ class install(Command): def has_headers(self): ... def has_scripts(self): ... def has_data(self): ... - sub_commands: Any + sub_commands: ClassVar[list[tuple[str, Callable[[Self], bool] | None]]] diff --git a/stdlib/distutils/command/register.pyi b/stdlib/distutils/command/register.pyi index f88b94113ff4..9e46e2d4f828 100644 --- a/stdlib/distutils/command/register.pyi +++ b/stdlib/distutils/command/register.pyi @@ -1,10 +1,12 @@ -from typing import Any +from collections.abc import Callable +from typing import Any, ClassVar +from typing_extensions import Self from ..config import PyPIRCCommand class register(PyPIRCCommand): description: str - sub_commands: Any + sub_commands: ClassVar[list[tuple[str, Callable[[Self], bool] | None]]] list_classifiers: int strict: int def initialize_options(self) -> None: ... diff --git a/stdlib/distutils/command/sdist.pyi b/stdlib/distutils/command/sdist.pyi index 636c4a351d19..844e94dae474 100644 --- a/stdlib/distutils/command/sdist.pyi +++ b/stdlib/distutils/command/sdist.pyi @@ -1,4 +1,6 @@ -from typing import Any +from collections.abc import Callable +from typing import Any, ClassVar +from typing_extensions import Self from ..cmd import Command @@ -11,7 +13,7 @@ class sdist(Command): boolean_options: Any help_options: Any negative_opt: Any - sub_commands: Any + sub_commands: ClassVar[list[tuple[str, Callable[[Self], bool] | None]]] READMES: Any template: Any manifest: Any From e5af19a9b5db7b44ccd78f168f8ee17c530deb77 Mon Sep 17 00:00:00 2001 From: Avasam Date: Fri, 17 May 2024 23:43:15 -0400 Subject: [PATCH 2/3] Add type ignore comments --- stdlib/distutils/command/build.pyi | 3 ++- stdlib/distutils/command/install.pyi | 3 ++- stdlib/distutils/command/register.pyi | 3 ++- stdlib/distutils/command/sdist.pyi | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/stdlib/distutils/command/build.pyi b/stdlib/distutils/command/build.pyi index 43400a8fb1f8..0a9e5bea8800 100644 --- a/stdlib/distutils/command/build.pyi +++ b/stdlib/distutils/command/build.pyi @@ -30,4 +30,5 @@ class build(Command): def has_c_libraries(self): ... def has_ext_modules(self): ... def has_scripts(self): ... - sub_commands: ClassVar[list[tuple[str, Callable[[Self], bool] | None]]] + # The callable parameter is self: Self, but using Self still trips up mypy + sub_commands: ClassVar[list[tuple[str, Callable[[Self], bool] | None]]] # type: ignore[assignment] diff --git a/stdlib/distutils/command/install.pyi b/stdlib/distutils/command/install.pyi index 1f3c7514a1bc..9338bbeea8b9 100644 --- a/stdlib/distutils/command/install.pyi +++ b/stdlib/distutils/command/install.pyi @@ -62,4 +62,5 @@ class install(Command): def has_headers(self): ... def has_scripts(self): ... def has_data(self): ... - sub_commands: ClassVar[list[tuple[str, Callable[[Self], bool] | None]]] + # The callable parameter is self: Self, but using Self still trips up mypy + sub_commands: ClassVar[list[tuple[str, Callable[[Self], bool] | None]]] # type: ignore[assignment] diff --git a/stdlib/distutils/command/register.pyi b/stdlib/distutils/command/register.pyi index 9e46e2d4f828..f7a0f5cf3f4a 100644 --- a/stdlib/distutils/command/register.pyi +++ b/stdlib/distutils/command/register.pyi @@ -6,7 +6,8 @@ from ..config import PyPIRCCommand class register(PyPIRCCommand): description: str - sub_commands: ClassVar[list[tuple[str, Callable[[Self], bool] | None]]] + # The callable parameter is self: Self, but using Self still trips up mypy + sub_commands: ClassVar[list[tuple[str, Callable[[Self], bool] | None]]] # type: ignore[assignment] list_classifiers: int strict: int def initialize_options(self) -> None: ... diff --git a/stdlib/distutils/command/sdist.pyi b/stdlib/distutils/command/sdist.pyi index 844e94dae474..22dfa33d3fd3 100644 --- a/stdlib/distutils/command/sdist.pyi +++ b/stdlib/distutils/command/sdist.pyi @@ -13,7 +13,8 @@ class sdist(Command): boolean_options: Any help_options: Any negative_opt: Any - sub_commands: ClassVar[list[tuple[str, Callable[[Self], bool] | None]]] + # The callable parameter is self: Self, but using Self still trips up mypy + sub_commands: ClassVar[list[tuple[str, Callable[[Self], bool] | None]]] # type: ignore[assignment] READMES: Any template: Any manifest: Any From 76fa80983cd1c14f64b2df8b858c277722eb9770 Mon Sep 17 00:00:00 2001 From: Avasam Date: Sat, 18 May 2024 01:29:38 -0400 Subject: [PATCH 3/3] Any instead of Self --- stdlib/distutils/cmd.pyi | 4 ++-- stdlib/distutils/command/build.pyi | 5 ++--- stdlib/distutils/command/install.pyi | 5 ++--- stdlib/distutils/command/register.pyi | 5 ++--- stdlib/distutils/command/sdist.pyi | 5 ++--- stubs/setuptools/setuptools/_distutils/cmd.pyi | 6 +++--- stubs/setuptools/setuptools/command/install.pyi | 4 +++- stubs/setuptools/setuptools/command/upload_docs.pyi | 5 ++--- 8 files changed, 18 insertions(+), 21 deletions(-) diff --git a/stdlib/distutils/cmd.pyi b/stdlib/distutils/cmd.pyi index 0b4dee6ecafa..df0896a75308 100644 --- a/stdlib/distutils/cmd.pyi +++ b/stdlib/distutils/cmd.pyi @@ -3,11 +3,11 @@ from abc import abstractmethod from collections.abc import Callable, Iterable from distutils.dist import Distribution from typing import Any, ClassVar, Literal -from typing_extensions import Self class Command: distribution: Distribution - sub_commands: ClassVar[list[tuple[str, Callable[[Self], bool] | None]]] + # Any to work around variance issues + sub_commands: ClassVar[list[tuple[str, Callable[[Any], bool] | None]]] def __init__(self, dist: Distribution) -> None: ... @abstractmethod def initialize_options(self) -> None: ... diff --git a/stdlib/distutils/command/build.pyi b/stdlib/distutils/command/build.pyi index 0a9e5bea8800..31fc036d4f97 100644 --- a/stdlib/distutils/command/build.pyi +++ b/stdlib/distutils/command/build.pyi @@ -1,6 +1,5 @@ from collections.abc import Callable from typing import Any, ClassVar -from typing_extensions import Self from ..cmd import Command @@ -30,5 +29,5 @@ class build(Command): def has_c_libraries(self): ... def has_ext_modules(self): ... def has_scripts(self): ... - # The callable parameter is self: Self, but using Self still trips up mypy - sub_commands: ClassVar[list[tuple[str, Callable[[Self], bool] | None]]] # type: ignore[assignment] + # Any to work around variance issues + sub_commands: ClassVar[list[tuple[str, Callable[[Any], bool] | None]]] diff --git a/stdlib/distutils/command/install.pyi b/stdlib/distutils/command/install.pyi index 9338bbeea8b9..8b2295d7a3c7 100644 --- a/stdlib/distutils/command/install.pyi +++ b/stdlib/distutils/command/install.pyi @@ -1,6 +1,5 @@ from collections.abc import Callable from typing import Any, ClassVar -from typing_extensions import Self from ..cmd import Command @@ -62,5 +61,5 @@ class install(Command): def has_headers(self): ... def has_scripts(self): ... def has_data(self): ... - # The callable parameter is self: Self, but using Self still trips up mypy - sub_commands: ClassVar[list[tuple[str, Callable[[Self], bool] | None]]] # type: ignore[assignment] + # Any to work around variance issues + sub_commands: ClassVar[list[tuple[str, Callable[[Any], bool] | None]]] diff --git a/stdlib/distutils/command/register.pyi b/stdlib/distutils/command/register.pyi index f7a0f5cf3f4a..a5e251d2d01e 100644 --- a/stdlib/distutils/command/register.pyi +++ b/stdlib/distutils/command/register.pyi @@ -1,13 +1,12 @@ from collections.abc import Callable from typing import Any, ClassVar -from typing_extensions import Self from ..config import PyPIRCCommand class register(PyPIRCCommand): description: str - # The callable parameter is self: Self, but using Self still trips up mypy - sub_commands: ClassVar[list[tuple[str, Callable[[Self], bool] | None]]] # type: ignore[assignment] + # Any to work around variance issues + sub_commands: ClassVar[list[tuple[str, Callable[[Any], bool] | None]]] list_classifiers: int strict: int def initialize_options(self) -> None: ... diff --git a/stdlib/distutils/command/sdist.pyi b/stdlib/distutils/command/sdist.pyi index 22dfa33d3fd3..db303f77a463 100644 --- a/stdlib/distutils/command/sdist.pyi +++ b/stdlib/distutils/command/sdist.pyi @@ -1,6 +1,5 @@ from collections.abc import Callable from typing import Any, ClassVar -from typing_extensions import Self from ..cmd import Command @@ -13,8 +12,8 @@ class sdist(Command): boolean_options: Any help_options: Any negative_opt: Any - # The callable parameter is self: Self, but using Self still trips up mypy - sub_commands: ClassVar[list[tuple[str, Callable[[Self], bool] | None]]] # type: ignore[assignment] + # Any to work around variance issues + sub_commands: ClassVar[list[tuple[str, Callable[[Any], bool] | None]]] READMES: Any template: Any manifest: Any diff --git a/stubs/setuptools/setuptools/_distutils/cmd.pyi b/stubs/setuptools/setuptools/_distutils/cmd.pyi index f67086103d07..aff61064444e 100644 --- a/stubs/setuptools/setuptools/_distutils/cmd.pyi +++ b/stubs/setuptools/setuptools/_distutils/cmd.pyi @@ -1,14 +1,14 @@ from _typeshed import Incomplete, Unused from abc import abstractmethod from collections.abc import Callable, Iterable -from typing import ClassVar, Literal -from typing_extensions import Self +from typing import Any, ClassVar, Literal from .dist import Distribution class Command: distribution: Distribution - sub_commands: ClassVar[list[tuple[str, Callable[[Self], bool] | None]]] + # Any to work around variance issues + sub_commands: ClassVar[list[tuple[str, Callable[[Any], bool] | None]]] def __init__(self, dist: Distribution) -> None: ... def ensure_finalized(self) -> None: ... @abstractmethod diff --git a/stubs/setuptools/setuptools/command/install.pyi b/stubs/setuptools/setuptools/command/install.pyi index aa2aabf730c7..b5fa8d634047 100644 --- a/stubs/setuptools/setuptools/command/install.pyi +++ b/stubs/setuptools/setuptools/command/install.pyi @@ -1,3 +1,4 @@ +from collections.abc import Callable from typing import Any from .._distutils.command import install as orig @@ -5,7 +6,8 @@ from .._distutils.command import install as orig class install(orig.install): user_options: Any boolean_options: Any - new_commands: Any + # Any to work around variance issues + new_commands: list[tuple[str, Callable[[Any], bool]] | None] old_and_unmanageable: Any single_version_externally_managed: Any def initialize_options(self) -> None: ... diff --git a/stubs/setuptools/setuptools/command/upload_docs.pyi b/stubs/setuptools/setuptools/command/upload_docs.pyi index 4ba85986146a..57e0c20ec7e2 100644 --- a/stubs/setuptools/setuptools/command/upload_docs.pyi +++ b/stubs/setuptools/setuptools/command/upload_docs.pyi @@ -1,6 +1,5 @@ from collections.abc import Callable from typing import Any, ClassVar -from typing_extensions import Self from .upload import upload @@ -10,8 +9,8 @@ class upload_docs(upload): user_options: ClassVar[list[tuple[str, str | None, str]]] boolean_options: ClassVar[list[str]] def has_sphinx(self): ... - # The callable parameter is self: Self, but using Self still trips up mypy - sub_commands: ClassVar[list[tuple[str, Callable[[Self], bool] | None]]] # type: ignore[assignment] + # Any to work around variance issues + sub_commands: ClassVar[list[tuple[str, Callable[[Any], bool] | None]]] upload_dir: Any target_dir: Any def initialize_options(self) -> None: ...