Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions setuptools/_distutils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import sysconfig
import tempfile
from collections.abc import Callable, Iterable, Mapping
from typing import TYPE_CHECKING, AnyStr
from typing import TYPE_CHECKING, TypeVar

from jaraco.functools import pass_none

Expand All @@ -31,6 +31,8 @@

_Ts = TypeVarTuple("_Ts")

_StrBytes = TypeVar("_StrBytes", str, bytes)


def get_host_platform() -> str:
"""
Expand Down Expand Up @@ -140,8 +142,8 @@ def convert_path(pathname: str | os.PathLike[str]) -> str:


def change_root(
new_root: AnyStr | os.PathLike[AnyStr], pathname: AnyStr | os.PathLike[AnyStr]
) -> AnyStr:
new_root: _StrBytes | os.PathLike[_StrBytes], pathname: _StrBytes | os.PathLike[_StrBytes]
) -> _StrBytes:
"""Return 'pathname' with 'new_root' prepended. If 'pathname' is
relative, this is equivalent to "os.path.join(new_root,pathname)".
Otherwise, it requires making 'pathname' relative and then joining the
Expand Down
8 changes: 5 additions & 3 deletions setuptools/command/bdist_egg.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from collections.abc import Iterator
from sysconfig import get_path, get_platform, get_python_version
from types import CodeType
from typing import TYPE_CHECKING, AnyStr, Literal
from typing import TYPE_CHECKING, Literal, TypeVar

from setuptools import Command
from setuptools.extension import Library
Expand All @@ -27,6 +27,8 @@

from _typeshed import GenericPath

_StrOrBytesT = TypeVar("_StrOrBytesT", bound=str | bytes)

# Same as zipfile._ZipFileMode from typeshed
_ZipFileMode: TypeAlias = Literal["r", "w", "x", "a"]

Expand All @@ -43,8 +45,8 @@ def strip_module(filename):


def sorted_walk(
dir: GenericPath[AnyStr],
) -> Iterator[tuple[AnyStr, list[AnyStr], list[AnyStr]]]:
dir: GenericPath[_StrOrBytesT],
) -> Iterator[tuple[_StrOrBytesT, list[_StrOrBytesT], list[_StrOrBytesT]]]:
"""Do os.walk in a reproducible way,
independent of indeterministic filesystem readdir order
"""
Expand Down
12 changes: 7 additions & 5 deletions setuptools/glob.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@
import os
import re
from collections.abc import Iterable, Iterator
from typing import TYPE_CHECKING, AnyStr, overload
from typing import TYPE_CHECKING, TypeVar, overload

if TYPE_CHECKING:
from _typeshed import BytesPath, StrOrBytesPath, StrPath

_StrOrBytesT = TypeVar("_StrOrBytesT", bound=str | bytes)

__all__ = ["glob", "iglob", "escape"]


def glob(pathname: AnyStr, recursive: bool = False) -> list[AnyStr]:
def glob(pathname: _StrOrBytesT, recursive: bool = False) -> list[_StrOrBytesT]:
"""Return a list of paths matching a pathname pattern.

The pattern may contain simple shell-style wildcards a la
Expand All @@ -34,7 +36,7 @@ def glob(pathname: AnyStr, recursive: bool = False) -> list[AnyStr]:
return list(iglob(pathname, recursive=recursive))


def iglob(pathname: AnyStr, recursive: bool = False) -> Iterator[AnyStr]:
def iglob(pathname: _StrOrBytesT, recursive: bool = False) -> Iterator[_StrOrBytesT]:
"""Return an iterator which yields the paths matching a pathname pattern.

The pattern may contain simple shell-style wildcards a la
Expand All @@ -52,7 +54,7 @@ def iglob(pathname: AnyStr, recursive: bool = False) -> Iterator[AnyStr]:
return it


def _iglob(pathname: AnyStr, recursive: bool) -> Iterator[AnyStr]:
def _iglob(pathname: _StrOrBytesT, recursive: bool) -> Iterator[_StrOrBytesT]:
dirname, basename = os.path.split(pathname)
glob_in_dir = glob2 if recursive and _isrecursive(basename) else glob1

Expand All @@ -73,7 +75,7 @@ def _iglob(pathname: AnyStr, recursive: bool) -> Iterator[AnyStr]:
# drive or UNC path. Prevent an infinite recursion if a drive or UNC path
# contains magic characters (i.e. r'\\?\C:').
if dirname != pathname and has_magic(dirname):
dirs: Iterable[AnyStr] = _iglob(dirname, recursive)
dirs: Iterable[_StrOrBytesT] = _iglob(dirname, recursive)
else:
dirs = [dirname]
if not has_magic(basename):
Expand Down