Skip to content

Commit e0eb9ce

Browse files
committed
Remove typing.AnyStr usage
1 parent 84ed591 commit e0eb9ce

3 files changed

Lines changed: 17 additions & 11 deletions

File tree

setuptools/_distutils/util.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import sysconfig
1818
import tempfile
1919
from collections.abc import Callable, Iterable, Mapping
20-
from typing import TYPE_CHECKING, AnyStr
20+
from typing import TYPE_CHECKING, TypeVar
2121

2222
from jaraco.functools import pass_none
2323

@@ -31,6 +31,8 @@
3131

3232
_Ts = TypeVarTuple("_Ts")
3333

34+
_StrBytes = TypeVar("_StrBytes", str, bytes)
35+
3436

3537
def get_host_platform() -> str:
3638
"""
@@ -140,8 +142,8 @@ def convert_path(pathname: str | os.PathLike[str]) -> str:
140142

141143

142144
def change_root(
143-
new_root: AnyStr | os.PathLike[AnyStr], pathname: AnyStr | os.PathLike[AnyStr]
144-
) -> AnyStr:
145+
new_root: _StrBytes | os.PathLike[_StrBytes], pathname: _StrBytes | os.PathLike[_StrBytes]
146+
) -> _StrBytes:
145147
"""Return 'pathname' with 'new_root' prepended. If 'pathname' is
146148
relative, this is equivalent to "os.path.join(new_root,pathname)".
147149
Otherwise, it requires making 'pathname' relative and then joining the

setuptools/command/bdist_egg.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from collections.abc import Iterator
1313
from sysconfig import get_path, get_platform, get_python_version
1414
from types import CodeType
15-
from typing import TYPE_CHECKING, AnyStr, Literal
15+
from typing import TYPE_CHECKING, Literal, TypeVar
1616

1717
from setuptools import Command
1818
from setuptools.extension import Library
@@ -27,6 +27,8 @@
2727

2828
from _typeshed import GenericPath
2929

30+
_StrOrBytesT = TypeVar("_StrOrBytesT", bound=str | bytes)
31+
3032
# Same as zipfile._ZipFileMode from typeshed
3133
_ZipFileMode: TypeAlias = Literal["r", "w", "x", "a"]
3234

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

4446

4547
def sorted_walk(
46-
dir: GenericPath[AnyStr],
47-
) -> Iterator[tuple[AnyStr, list[AnyStr], list[AnyStr]]]:
48+
dir: GenericPath[_StrOrBytesT],
49+
) -> Iterator[tuple[_StrOrBytesT, list[_StrOrBytesT], list[_StrOrBytesT]]]:
4850
"""Do os.walk in a reproducible way,
4951
independent of indeterministic filesystem readdir order
5052
"""

setuptools/glob.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@
1212
import os
1313
import re
1414
from collections.abc import Iterable, Iterator
15-
from typing import TYPE_CHECKING, AnyStr, overload
15+
from typing import TYPE_CHECKING, TypeVar, overload
1616

1717
if TYPE_CHECKING:
1818
from _typeshed import BytesPath, StrOrBytesPath, StrPath
1919

20+
_StrOrBytesT = TypeVar("_StrOrBytesT", bound=str | bytes)
21+
2022
__all__ = ["glob", "iglob", "escape"]
2123

2224

23-
def glob(pathname: AnyStr, recursive: bool = False) -> list[AnyStr]:
25+
def glob(pathname: _StrOrBytesT, recursive: bool = False) -> list[_StrOrBytesT]:
2426
"""Return a list of paths matching a pathname pattern.
2527
2628
The pattern may contain simple shell-style wildcards a la
@@ -34,7 +36,7 @@ def glob(pathname: AnyStr, recursive: bool = False) -> list[AnyStr]:
3436
return list(iglob(pathname, recursive=recursive))
3537

3638

37-
def iglob(pathname: AnyStr, recursive: bool = False) -> Iterator[AnyStr]:
39+
def iglob(pathname: _StrOrBytesT, recursive: bool = False) -> Iterator[_StrOrBytesT]:
3840
"""Return an iterator which yields the paths matching a pathname pattern.
3941
4042
The pattern may contain simple shell-style wildcards a la
@@ -52,7 +54,7 @@ def iglob(pathname: AnyStr, recursive: bool = False) -> Iterator[AnyStr]:
5254
return it
5355

5456

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

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

0 commit comments

Comments
 (0)