1212import os
1313import re
1414from collections .abc import Iterable , Iterator
15- from typing import TYPE_CHECKING , AnyStr , overload
15+ from typing import TYPE_CHECKING , TypeVar , overload
1616
1717if 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