@@ -6,7 +6,7 @@ import sys
66import types
77from _typeshed import ReadableBuffer , StrOrBytesPath , StrPath
88from _typeshed .importlib import LoaderProtocol
9- from collections .abc import Callable , Iterable , Mapping , MutableSequence , Sequence
9+ from collections .abc import Callable , Iterable , Mapping , MutableSequence , Sequence , Iterator
1010from importlib .machinery import ModuleSpec
1111from importlib .metadata import DistributionFinder , PathDistribution
1212from typing import Any , Final , Literal , overload
@@ -23,13 +23,17 @@ else:
2323
2424MAGIC_NUMBER : Final [bytes ]
2525
26- @overload
27- @deprecated (
28- "The `debug_override` parameter is deprecated since Python 3.5; will be removed in Python 3.15. Use `optimization` instead."
29- )
30- def cache_from_source (path : StrPath , debug_override : bool , * , optimization : None = None ) -> str : ...
31- @overload
32- def cache_from_source (path : StrPath , debug_override : None = None , * , optimization : Any | None = None ) -> str : ...
26+ if sys .version_info >= (3 , 15 ):
27+ def cache_from_source (path : StrPath , * , optimization : Any | None = None ) -> str : ...
28+
29+ else :
30+ @overload
31+ @deprecated (
32+ "The `debug_override` parameter is deprecated since Python 3.5; will be removed in Python 3.15. Use `optimization` instead."
33+ )
34+ def cache_from_source (path : StrPath , debug_override : bool , * , optimization : None = None ) -> str : ...
35+ @overload
36+ def cache_from_source (path : StrPath , debug_override : None = None , * , optimization : Any | None = None ) -> str : ...
3337
3438def source_from_cache (path : StrPath ) -> str : ...
3539def decode_source (source_bytes : ReadableBuffer ) -> str : ...
@@ -70,6 +74,10 @@ class PathFinder(importlib.abc.MetaPathFinder):
7074 @deprecated ("Deprecated since Python 3.4; removed in Python 3.12. Use `find_spec()` instead." )
7175 def find_module (cls , fullname : str , path : Sequence [str ] | None = None ) -> importlib .abc .Loader | None : ...
7276
77+ if sys .version_info >= (3 , 15 ):
78+ @classmethod
79+ def discover (cls , parent : ModuleSpec | None = None ) -> Iterator [ModuleSpec ]: ...
80+
7381SOURCE_SUFFIXES : Final [list [str ]]
7482DEBUG_BYTECODE_SUFFIXES : Final = [".pyc" ]
7583OPTIMIZED_BYTECODE_SUFFIXES : Final = [".pyc" ]
@@ -83,21 +91,33 @@ class FileFinder(importlib.abc.PathEntryFinder):
8391 def path_hook (
8492 cls , * loader_details : tuple [type [importlib .abc .Loader ], list [str ]]
8593 ) -> Callable [[str ], importlib .abc .PathEntryFinder ]: ...
94+ if sys .version_info >= (3 , 15 ):
95+ def discover (self , parent : ModuleSpec | None = None ) -> Iterator [ModuleSpec ]: ...
8696
8797class _LoaderBasics :
8898 def is_package (self , fullname : str ) -> bool : ...
8999 def create_module (self , spec : ModuleSpec ) -> types .ModuleType | None : ...
90100 def exec_module (self , module : types .ModuleType ) -> None : ...
91- def load_module (self , fullname : str ) -> types .ModuleType : ...
101+ if sys .version_info < (3 , 15 ):
102+ @deprecated ("Deprecated since Python 3.4; removed in Python 3.15. Use `exec_module()` instead." )
103+ def load_module (self , fullname : str ) -> types .ModuleType : ...
92104
93105class SourceLoader (_LoaderBasics ):
94106 def path_mtime (self , path : str ) -> float : ...
95107 def set_data (self , path : str , data : bytes ) -> None : ...
96108 def get_source (self , fullname : str ) -> str | None : ...
97109 def path_stats (self , path : str ) -> Mapping [str , Any ]: ...
98- def source_to_code (
99- self , data : ReadableBuffer | str | _ast .Module | _ast .Expression | _ast .Interactive , path : bytes | StrPath
100- ) -> types .CodeType : ...
110+ if sys .version_info >= (3 , 15 ):
111+ def source_to_code (
112+ self ,
113+ data : ReadableBuffer | str | _ast .Module | _ast .Expression | _ast .Interactive ,
114+ path : bytes | StrPath ,
115+ fullname : str | None = None ,
116+ ) -> types .CodeType : ...
117+ else :
118+ def source_to_code (
119+ self , data : ReadableBuffer | str | _ast .Module | _ast .Expression | _ast .Interactive , path : bytes | StrPath
120+ ) -> types .CodeType : ...
101121 def get_code (self , fullname : str ) -> types .CodeType | None : ...
102122
103123class FileLoader :
@@ -112,13 +132,23 @@ class FileLoader:
112132class SourceFileLoader (importlib .abc .FileLoader , FileLoader , importlib .abc .SourceLoader , SourceLoader ): # type: ignore[misc] # incompatible method arguments in base classes
113133 def set_data (self , path : str , data : ReadableBuffer , * , _mode : int = 0o666 ) -> None : ...
114134 def path_stats (self , path : str ) -> Mapping [str , Any ]: ...
115- def source_to_code ( # type: ignore[override] # incompatible with InspectLoader.source_to_code
116- self ,
117- data : ReadableBuffer | str | _ast .Module | _ast .Expression | _ast .Interactive ,
118- path : bytes | StrPath ,
119- * ,
120- _optimize : int = - 1 ,
121- ) -> types .CodeType : ...
135+ if sys .version_info >= (3 , 15 ):
136+ def source_to_code ( # type: ignore[override] # incompatible with InspectLoader.source_to_code
137+ self ,
138+ data : ReadableBuffer | str | _ast .Module | _ast .Expression | _ast .Interactive ,
139+ path : bytes | StrPath ,
140+ fullname : str | None = None ,
141+ * ,
142+ _optimize : int = - 1 ,
143+ ) -> types .CodeType : ...
144+ else :
145+ def source_to_code ( # type: ignore[override] # incompatible with InspectLoader.source_to_code
146+ self ,
147+ data : ReadableBuffer | str | _ast .Module | _ast .Expression | _ast .Interactive ,
148+ path : bytes | StrPath ,
149+ * ,
150+ _optimize : int = - 1 ,
151+ ) -> types .CodeType : ...
122152
123153class SourcelessFileLoader (importlib .abc .FileLoader , FileLoader , _LoaderBasics ):
124154 def get_code (self , fullname : str ) -> types .CodeType | None : ...
@@ -134,6 +164,20 @@ class ExtensionFileLoader(FileLoader, _LoaderBasics, importlib.abc.ExecutionLoad
134164 def __eq__ (self , other : object ) -> bool : ...
135165 def __hash__ (self ) -> int : ...
136166
167+ if sys .version_info >= (3 , 15 ):
168+ class NamespacePath :
169+ def __init__ (
170+ self , name : str , path : MutableSequence [str ], path_finder : Callable [[str , tuple [str , ...]], ModuleSpec ]
171+ ) -> None : ...
172+ def __iter__ (self ) -> Iterator [str ]: ...
173+ def __getitem__ (self , index : int ) -> str : ...
174+ def __setitem__ (self , index : int , path : str ) -> None : ...
175+ def __len__ (self ) -> int : ...
176+ def __contains__ (self , item : str ) -> bool : ...
177+ def append (self , item : str ) -> None : ...
178+
179+ _NamespacePath = NamespacePath
180+
137181if sys .version_info >= (3 , 11 ):
138182 class NamespaceLoader (importlib .abc .InspectLoader ):
139183 def __init__ (
@@ -144,8 +188,9 @@ if sys.version_info >= (3, 11):
144188 def get_code (self , fullname : str ) -> types .CodeType : ...
145189 def create_module (self , spec : ModuleSpec ) -> None : ...
146190 def exec_module (self , module : types .ModuleType ) -> None : ...
147- @deprecated ("Deprecated since Python 3.10; will be removed in Python 3.15. Use `exec_module()` instead." )
148- def load_module (self , fullname : str ) -> types .ModuleType : ...
191+ if sys .version_info < (3 , 15 ):
192+ @deprecated ("Deprecated since Python 3.10; removed in Python 3.15. Use `exec_module()` instead." )
193+ def load_module (self , fullname : str ) -> types .ModuleType : ...
149194 def get_resource_reader (self , module : types .ModuleType ) -> importlib .readers .NamespaceReader : ...
150195 if sys .version_info < (3 , 12 ):
151196 @staticmethod
@@ -178,3 +223,5 @@ else:
178223
179224if sys .version_info >= (3 , 13 ):
180225 class AppleFrameworkLoader (ExtensionFileLoader , importlib .abc .ExecutionLoader ): ...
226+
227+
0 commit comments