1
1
import sys
2
2
import types
3
- from _typeshed import OpenBinaryMode , OpenBinaryModeReading , OpenBinaryModeUpdating , OpenBinaryModeWriting , OpenTextMode
3
+ from _typeshed import (
4
+ OpenBinaryMode ,
5
+ OpenBinaryModeReading ,
6
+ OpenBinaryModeUpdating ,
7
+ OpenBinaryModeWriting ,
8
+ OpenTextMode ,
9
+ ReadableBuffer ,
10
+ )
4
11
from abc import ABCMeta , abstractmethod
5
12
from collections .abc import Iterator , Mapping , Sequence
6
13
from importlib .machinery import ModuleSpec
7
14
from io import BufferedRandom , BufferedReader , BufferedWriter , FileIO , TextIOWrapper
8
15
from typing import IO , Any , BinaryIO , NoReturn , Protocol , overload , runtime_checkable
9
- from typing_extensions import Literal , TypeAlias
16
+ from typing_extensions import Literal
10
17
11
18
if sys .version_info >= (3 , 11 ):
12
19
__all__ = [
@@ -24,8 +31,6 @@ if sys.version_info >= (3, 11):
24
31
"TraversableResources" ,
25
32
]
26
33
27
- _Path : TypeAlias = bytes | str
28
-
29
34
class Finder (metaclass = ABCMeta ): ...
30
35
31
36
class Loader (metaclass = ABCMeta ):
@@ -38,7 +43,7 @@ class Loader(metaclass=ABCMeta):
38
43
39
44
class ResourceLoader (Loader ):
40
45
@abstractmethod
41
- def get_data (self , path : _Path ) -> bytes : ...
46
+ def get_data (self , path : str ) -> bytes : ...
42
47
43
48
class InspectLoader (Loader ):
44
49
def is_package (self , fullname : str ) -> bool : ...
@@ -47,40 +52,40 @@ class InspectLoader(Loader):
47
52
def get_source (self , fullname : str ) -> str | None : ...
48
53
def exec_module (self , module : types .ModuleType ) -> None : ...
49
54
@staticmethod
50
- def source_to_code (data : bytes | str , path : str = ...) -> types .CodeType : ...
55
+ def source_to_code (data : ReadableBuffer | str , path : str = ...) -> types .CodeType : ...
51
56
52
57
class ExecutionLoader (InspectLoader ):
53
58
@abstractmethod
54
- def get_filename (self , fullname : str ) -> _Path : ...
59
+ def get_filename (self , fullname : str ) -> str : ...
55
60
56
61
class SourceLoader (ResourceLoader , ExecutionLoader , metaclass = ABCMeta ):
57
- def path_mtime (self , path : _Path ) -> float : ...
58
- def set_data (self , path : _Path , data : bytes ) -> None : ...
62
+ def path_mtime (self , path : str ) -> float : ...
63
+ def set_data (self , path : str , data : bytes ) -> None : ...
59
64
def get_source (self , fullname : str ) -> str | None : ...
60
- def path_stats (self , path : _Path ) -> Mapping [str , Any ]: ...
65
+ def path_stats (self , path : str ) -> Mapping [str , Any ]: ...
61
66
62
67
# Please keep in sync with sys._MetaPathFinder
63
68
class MetaPathFinder (Finder ):
64
- def find_module (self , fullname : str , path : Sequence [_Path ] | None ) -> Loader | None : ...
69
+ def find_module (self , fullname : str , path : Sequence [str ] | None ) -> Loader | None : ...
65
70
def invalidate_caches (self ) -> None : ...
66
71
# Not defined on the actual class, but expected to exist.
67
72
def find_spec (
68
- self , fullname : str , path : Sequence [_Path ] | None , target : types .ModuleType | None = ...
73
+ self , fullname : str , path : Sequence [str ] | None , target : types .ModuleType | None = ...
69
74
) -> ModuleSpec | None : ...
70
75
71
76
class PathEntryFinder (Finder ):
72
77
def find_module (self , fullname : str ) -> Loader | None : ...
73
- def find_loader (self , fullname : str ) -> tuple [Loader | None , Sequence [_Path ]]: ...
78
+ def find_loader (self , fullname : str ) -> tuple [Loader | None , Sequence [str ]]: ...
74
79
def invalidate_caches (self ) -> None : ...
75
80
# Not defined on the actual class, but expected to exist.
76
81
def find_spec (self , fullname : str , target : types .ModuleType | None = ...) -> ModuleSpec | None : ...
77
82
78
83
class FileLoader (ResourceLoader , ExecutionLoader , metaclass = ABCMeta ):
79
84
name : str
80
- path : _Path
81
- def __init__ (self , fullname : str , path : _Path ) -> None : ...
82
- def get_data (self , path : _Path ) -> bytes : ...
83
- def get_filename (self , name : str | None = ...) -> _Path : ...
85
+ path : str
86
+ def __init__ (self , fullname : str , path : str ) -> None : ...
87
+ def get_data (self , path : str ) -> bytes : ...
88
+ def get_filename (self , name : str | None = ...) -> str : ...
84
89
def load_module (self , name : str | None = ...) -> types .ModuleType : ...
85
90
86
91
class ResourceReader (metaclass = ABCMeta ):
0 commit comments