Skip to content

Commit

Permalink
Sync with typeshed post-#4504 (#4719)
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri authored Oct 31, 2024
2 parents 0f6055c + 1183377 commit b88d0a1
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion setuptools/command/bdist_egg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
9 changes: 5 additions & 4 deletions setuptools/command/editable_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: ...


Expand Down
3 changes: 2 additions & 1 deletion setuptools/command/rotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
import shutil
from typing import ClassVar

from setuptools import Command

Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion setuptools/config/expand.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions setuptools/config/pyprojecttoml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion setuptools/config/setupcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
TYPE_CHECKING,
Any,
Callable,
ClassVar,
Dict,
Generic,
Iterable,
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions setuptools/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions setuptools/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit b88d0a1

Please sign in to comment.