diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py index c9eee16a5d..2881d8a9da 100644 --- a/setuptools/command/bdist_egg.py +++ b/setuptools/command/bdist_egg.py @@ -322,7 +322,7 @@ def get_ext_outputs(self): return all_outputs, ext_outputs -NATIVE_EXTENSIONS = dict.fromkeys('.dll .so .dylib .pyd'.split()) +NATIVE_EXTENSIONS: dict[str, None] = dict.fromkeys('.dll .so .dylib .pyd'.split()) def walk_egg(egg_dir): diff --git a/setuptools/command/editable_wheel.py b/setuptools/command/editable_wheel.py index c1641a7267..34722e1aac 100644 --- a/setuptools/command/editable_wheel.py +++ b/setuptools/command/editable_wheel.py @@ -23,6 +23,7 @@ from itertools import chain, starmap from pathlib import Path from tempfile import TemporaryDirectory +from types import TracebackType from typing import TYPE_CHECKING, Iterable, Iterator, Mapping, Protocol, TypeVar, cast from .. import Command, _normalization, _path, errors, namespaces @@ -379,13 +380,13 @@ def _select_strategy( class EditableStrategy(Protocol): def __call__( self, wheel: WheelFile, files: list[str], mapping: Mapping[str, str] - ): ... + ) -> object: ... def __enter__(self) -> Self: ... def __exit__( self, - _exc_type: object, - _exc_value: object, - _traceback: object, + _exc_type: type[BaseException] | None, + _exc_value: BaseException | None, + _traceback: TracebackType | None, ) -> object: ... diff --git a/setuptools/command/rotate.py b/setuptools/command/rotate.py index dcdfafbcf7..76c7b8612e 100644 --- a/setuptools/command/rotate.py +++ b/setuptools/command/rotate.py @@ -2,6 +2,7 @@ import os import shutil +from typing import ClassVar from setuptools import Command @@ -20,7 +21,7 @@ class rotate(Command): ('keep=', 'k', "number of matching distributions to keep"), ] - boolean_options: list[str] = [] + boolean_options: ClassVar[list[str]] = [] def initialize_options(self): self.match = None diff --git a/setuptools/config/expand.py b/setuptools/config/expand.py index 81caf1c35e..c07314dd7f 100644 --- a/setuptools/config/expand.py +++ b/setuptools/config/expand.py @@ -354,7 +354,9 @@ def canonic_data_files( ] -def entry_points(text: str, text_source: str = "entry-points") -> dict[str, dict]: +def entry_points( + text: str, text_source: str = "entry-points" +) -> dict[str, dict[str, str]]: """Given the contents of entry-points file, process it into a 2-level dictionary (``dict[str, dict[str, str]]``). The first level keys are entry-point groups, the second level keys are diff --git a/setuptools/config/pyprojecttoml.py b/setuptools/config/pyprojecttoml.py index f5bda2ce34..cacd898264 100644 --- a/setuptools/config/pyprojecttoml.py +++ b/setuptools/config/pyprojecttoml.py @@ -330,7 +330,7 @@ def _obtain_readme(self, dist: Distribution) -> dict[str, str] | None: def _obtain_entry_points( self, dist: Distribution, package_dir: Mapping[str, str] - ) -> dict[str, dict] | None: + ) -> dict[str, dict[str, Any]] | None: fields = ("entry-points", "scripts", "gui-scripts") if not any(field in self.dynamic for field in fields): return None @@ -340,7 +340,8 @@ def _obtain_entry_points( return None groups = _expand.entry_points(text) - expanded = {"entry-points": groups} + # Any is str | dict[str, str], but causes variance issues + expanded: dict[str, dict[str, Any]] = {"entry-points": groups} def _set_scripts(field: str, group: str): if group in groups: diff --git a/setuptools/config/setupcfg.py b/setuptools/config/setupcfg.py index 35fe4f9aa9..7aafcf6680 100644 --- a/setuptools/config/setupcfg.py +++ b/setuptools/config/setupcfg.py @@ -20,6 +20,7 @@ TYPE_CHECKING, Any, Callable, + ClassVar, Dict, Generic, Iterable, @@ -245,7 +246,7 @@ class ConfigHandler(Generic[Target]): """ - aliases: dict[str, str] = {} + aliases: ClassVar[dict[str, str]] = {} """Options aliases. For compatibility with various packages. E.g.: d2to1 and pbr. Note: `-` in keys is replaced with `_` by config parser. diff --git a/setuptools/discovery.py b/setuptools/discovery.py index 09d1e2f474..9865552151 100644 --- a/setuptools/discovery.py +++ b/setuptools/discovery.py @@ -45,7 +45,7 @@ from fnmatch import fnmatchcase from glob import glob from pathlib import Path -from typing import TYPE_CHECKING, Iterable, Mapping +from typing import TYPE_CHECKING, ClassVar, Iterable, Mapping import _distutils_hack.override # noqa: F401 @@ -84,8 +84,8 @@ def __contains__(self, item: str) -> bool: class _Finder: """Base class that exposes functionality for module/package finders""" - ALWAYS_EXCLUDE: tuple[str, ...] = () - DEFAULT_EXCLUDE: tuple[str, ...] = () + ALWAYS_EXCLUDE: ClassVar[tuple[str, ...]] = () + DEFAULT_EXCLUDE: ClassVar[tuple[str, ...]] = () @classmethod def find( diff --git a/setuptools/sandbox.py b/setuptools/sandbox.py index ec5e79da05..5dedeeb47f 100644 --- a/setuptools/sandbox.py +++ b/setuptools/sandbox.py @@ -12,7 +12,7 @@ import tempfile import textwrap from types import TracebackType -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, ClassVar import pkg_resources from pkg_resources import working_set @@ -416,7 +416,7 @@ def _remap_pair(self, operation, src, dst, *args, **kw): class DirectorySandbox(AbstractSandbox): """Restrict operations to a single subdirectory - pseudo-chroot""" - write_ops: dict[str, None] = dict.fromkeys([ + write_ops: ClassVar[dict[str, None]] = dict.fromkeys([ "open", "chmod", "chown",