Skip to content
Merged
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
2 changes: 0 additions & 2 deletions stdlib/@tests/stubtest_allowlists/common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ _ctypes.CFuncPtr # stubtest erroneously thinks it can't be subclassed
_frozen_importlib_external.ExtensionFileLoader.get_filename
_frozen_importlib_external.FileLoader.get_filename
_frozen_importlib_external.FileLoader.get_resource_reader
_frozen_importlib_external.FileLoader.load_module

# Mismatch of default values of `report` parameter:
_markupbase.ParserBase.parse_comment
Expand Down Expand Up @@ -277,7 +276,6 @@ importlib._abc.Loader.exec_module # See Lib/importlib/_abc.py. Might be defined

# runtime is *args, **kwargs due to a wrapper; we have more accurate signatures in the stubs
importlib.abc.FileLoader.get_filename
importlib.abc.FileLoader.load_module

importlib.metadata._meta.SimplePath.joinpath # Runtime definition of protocol is incorrect

Expand Down
4 changes: 4 additions & 0 deletions stdlib/@tests/stubtest_allowlists/py310.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ typing(_extensions)?\.IO\.writelines
posixpath.join
ntpath.join

# runtime is *args, **kwargs due to a wrapper; we have more accurate signatures in the stubs
_frozen_importlib_external.FileLoader.load_module
importlib.abc.FileLoader.load_module


# ===============================================================
# Allowlist entries that cannot or should not be fixed; 3.10 only
Expand Down
4 changes: 4 additions & 0 deletions stdlib/@tests/stubtest_allowlists/py311.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ typing(_extensions)?\.IO\.writelines
posixpath.join
ntpath.join

# runtime is *args, **kwargs due to a wrapper; we have more accurate signatures in the stubs
_frozen_importlib_external.FileLoader.load_module
importlib.abc.FileLoader.load_module


# =============================================================
# Allowlist entries that cannot or should not be fixed; >= 3.11
Expand Down
4 changes: 4 additions & 0 deletions stdlib/@tests/stubtest_allowlists/py312.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ typing(_extensions)?\.IO\.writelines
posixpath.join
ntpath.join

# runtime is *args, **kwargs due to a wrapper; we have more accurate signatures in the stubs
_frozen_importlib_external.FileLoader.load_module
importlib.abc.FileLoader.load_module


# =============================================================
# Allowlist entries that cannot or should not be fixed; >= 3.12
Expand Down
4 changes: 4 additions & 0 deletions stdlib/@tests/stubtest_allowlists/py313.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ typing(_extensions)?\.IO\.writelines
posixpath.join
ntpath.join

# runtime is *args, **kwargs due to a wrapper; we have more accurate signatures in the stubs
_frozen_importlib_external.FileLoader.load_module
importlib.abc.FileLoader.load_module


# =============================================================
# Allowlist entries that cannot or should not be fixed; >= 3.13
Expand Down
4 changes: 4 additions & 0 deletions stdlib/@tests/stubtest_allowlists/py314.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ typing(_extensions)?\.IO\.writelines
posixpath.join
ntpath.join

# runtime is *args, **kwargs due to a wrapper; we have more accurate signatures in the stubs
_frozen_importlib_external.FileLoader.load_module
importlib.abc.FileLoader.load_module


# =============================================================
# Allowlist entries that cannot or should not be fixed; >= 3.14
Expand Down
12 changes: 0 additions & 12 deletions stdlib/@tests/stubtest_allowlists/py315.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,12 @@
# TODO: Allowlist entries that should be fixed
# ============================================

_frozen_importlib.BuiltinImporter.load_module
_frozen_importlib.FrozenImporter.load_module
_frozen_importlib_external.NamespaceLoader.load_module
_frozen_importlib_external.NamespacePath
_frozen_importlib_external.PathFinder.discover
_frozen_importlib_external.SourceFileLoader.source_to_code
_frozen_importlib_external.SourceLoader.source_to_code
_frozen_importlib_external._LoaderBasics.load_module
_frozen_importlib_external.cache_from_source
dataclasses.MISSING
dataclasses._MISSING_TYPE
dataclasses.field
importlib._abc.Loader.load_module
importlib._bootstrap_external.NamespacePath
importlib.resources._common.package_to_anchor
mailbox._ProxyFile.__class_getitem__

# =============================================================
Expand Down Expand Up @@ -144,9 +135,6 @@ typing_extensions.Protocol # Super-special typing primitive
# Allowlist entries that cannot or should not be fixed; >= 3.12
# =============================================================

# Deprecated argument is supported at runtime by renaming it through a decorator.
importlib.resources._common.files

sys._monitoring # Doesn't really exist. See comments in the stub.
sys.__jit # Similar to sys._monitoring
sys.last_exc # Not always defined.
Expand Down
14 changes: 10 additions & 4 deletions stdlib/_frozen_importlib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def __import__(
fromlist: Sequence[str] | None = (),
level: int = 0,
) -> ModuleType: ...

# TODO: Revise the protocol for 'loader' param
def spec_from_loader(
name: str, loader: LoaderProtocol | None, *, origin: str | None = None, is_package: bool | None = None
) -> importlib.machinery.ModuleSpec | None: ...
Expand Down Expand Up @@ -61,11 +63,13 @@ class BuiltinImporter(importlib.abc.MetaPathFinder, importlib.abc.InspectLoader)
@classmethod
def is_package(cls, fullname: str) -> bool: ...
@classmethod
def load_module(cls, fullname: str) -> types.ModuleType: ...
@classmethod
def get_code(cls, fullname: str) -> None: ...
@classmethod
def get_source(cls, fullname: str) -> None: ...
if sys.version_info < (3, 15):
@classmethod
@deprecated("Deprecated since Python 3.10; removed in Python 3.15. Use `exec_module()` instead.")
def load_module(cls, fullname: str) -> types.ModuleType: ...
# Loader
if sys.version_info < (3, 12):
@staticmethod
Expand Down Expand Up @@ -95,11 +99,13 @@ class FrozenImporter(importlib.abc.MetaPathFinder, importlib.abc.InspectLoader):
@classmethod
def is_package(cls, fullname: str) -> bool: ...
@classmethod
def load_module(cls, fullname: str) -> types.ModuleType: ...
@classmethod
def get_code(cls, fullname: str) -> None: ...
@classmethod
def get_source(cls, fullname: str) -> None: ...
if sys.version_info < (3, 15):
@classmethod
@deprecated("Deprecated since Python 3.10; removed in Python 3.15. Use `exec_module()` instead.")
def load_module(cls, fullname: str) -> types.ModuleType: ...
# Loader
if sys.version_info < (3, 12):
@staticmethod
Expand Down
47 changes: 34 additions & 13 deletions stdlib/_frozen_importlib_external.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import sys
import types
from _typeshed import ReadableBuffer, StrOrBytesPath, StrPath
from _typeshed.importlib import LoaderProtocol
from collections.abc import Callable, Iterable, Mapping, MutableSequence, Sequence
from collections.abc import Callable, Iterable, Iterator, Mapping, MutableSequence, Sequence
from importlib.machinery import ModuleSpec
from importlib.metadata import DistributionFinder, PathDistribution
from typing import Any, Final, Literal, overload
Expand All @@ -23,13 +23,17 @@ else:

MAGIC_NUMBER: Final[bytes]

@overload
@deprecated(
"The `debug_override` parameter is deprecated since Python 3.5; will be removed in Python 3.15. Use `optimization` instead."
)
def cache_from_source(path: StrPath, debug_override: bool, *, optimization: None = None) -> str: ...
@overload
def cache_from_source(path: StrPath, debug_override: None = None, *, optimization: Any | None = None) -> str: ...
if sys.version_info >= (3, 15):
def cache_from_source(path: StrPath, *, optimization: Any | None = None) -> str: ...

else:
@overload
@deprecated(
"The `debug_override` parameter is deprecated since Python 3.5; removed in Python 3.15. Use `optimization` instead."
)
def cache_from_source(path: StrPath, debug_override: bool, *, optimization: None = None) -> str: ...
@overload
def cache_from_source(path: StrPath, debug_override: None = None, *, optimization: Any | None = None) -> str: ...

def source_from_cache(path: StrPath) -> str: ...
def decode_source(source_bytes: ReadableBuffer) -> str: ...
Expand Down Expand Up @@ -88,7 +92,9 @@ class _LoaderBasics:
def is_package(self, fullname: str) -> bool: ...
def create_module(self, spec: ModuleSpec) -> types.ModuleType | None: ...
def exec_module(self, module: types.ModuleType) -> None: ...
def load_module(self, fullname: str) -> types.ModuleType: ...
if sys.version_info < (3, 15):
@deprecated("Deprecated since Python 3.10; removed in Python 3.15. Use `exec_module()` instead.")
def load_module(self, fullname: str) -> types.ModuleType: ...

class SourceLoader(_LoaderBasics):
def path_mtime(self, path: str) -> float: ...
Expand All @@ -106,8 +112,10 @@ class FileLoader:
def __init__(self, fullname: str, path: str) -> None: ...
def get_data(self, path: str) -> bytes: ...
def get_filename(self, fullname: str | None = None) -> str: ...
def load_module(self, fullname: str | None = None) -> types.ModuleType: ...
def get_resource_reader(self, name: str | None = None) -> importlib.readers.FileReader: ...
if sys.version_info < (3, 15):
@deprecated("Deprecated since Python 3.10; removed in Python 3.15. Use `exec_module()` instead.")
def load_module(self, fullname: str | None = None) -> types.ModuleType: ...

class SourceFileLoader(importlib.abc.FileLoader, FileLoader, importlib.abc.SourceLoader, SourceLoader): # type: ignore[misc] # incompatible method arguments in base classes
def set_data(self, path: str, data: ReadableBuffer, *, _mode: int = 0o666) -> None: ...
Expand All @@ -134,6 +142,18 @@ class ExtensionFileLoader(FileLoader, _LoaderBasics, importlib.abc.ExecutionLoad
def __eq__(self, other: object) -> bool: ...
def __hash__(self) -> int: ...

if sys.version_info >= (3, 15):
class NamespacePath:
def __init__(
self, name: str, path: MutableSequence[str], path_finder: Callable[[str, tuple[str, ...]], ModuleSpec]
) -> None: ...
def __iter__(self) -> Iterator[str]: ...
def __getitem__(self, index: int) -> str: ...
def __setitem__(self, index: int, path: str) -> None: ...
def __len__(self) -> int: ...
def __contains__(self, item: str) -> bool: ...
def append(self, item: str) -> None: ...

if sys.version_info >= (3, 11):
class NamespaceLoader(importlib.abc.InspectLoader):
def __init__(
Expand All @@ -144,9 +164,10 @@ if sys.version_info >= (3, 11):
def get_code(self, fullname: str) -> types.CodeType: ...
def create_module(self, spec: ModuleSpec) -> None: ...
def exec_module(self, module: types.ModuleType) -> None: ...
@deprecated("Deprecated since Python 3.10; will be removed in Python 3.15. Use `exec_module()` instead.")
def load_module(self, fullname: str) -> types.ModuleType: ...
def get_resource_reader(self, module: types.ModuleType) -> importlib.readers.NamespaceReader: ...
if sys.version_info < (3, 15):
@deprecated("Deprecated since Python 3.10; removed in Python 3.15. Use `exec_module()` instead.")
def load_module(self, fullname: str) -> types.ModuleType: ...
if sys.version_info < (3, 12):
@staticmethod
@deprecated(
Expand All @@ -166,7 +187,7 @@ else:
def get_code(self, fullname: str) -> types.CodeType: ...
def create_module(self, spec: ModuleSpec) -> None: ...
def exec_module(self, module: types.ModuleType) -> None: ...
@deprecated("Deprecated since Python 3.10; will be removed in Python 3.15. Use `exec_module()` instead.")
@deprecated("Deprecated since Python 3.10; removed in Python 3.15. Use `exec_module()` instead.")
def load_module(self, fullname: str) -> types.ModuleType: ...
@staticmethod
@deprecated(
Expand Down
4 changes: 3 additions & 1 deletion stdlib/importlib/_abc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ from importlib.machinery import ModuleSpec
from typing_extensions import deprecated

class Loader(metaclass=ABCMeta):
def load_module(self, fullname: str) -> types.ModuleType: ...
if sys.version_info < (3, 15):
@deprecated("Deprecated since Python 3.10; removed in Python 3.15. Use `exec_module()` instead.")
def load_module(self, fullname: str) -> types.ModuleType: ...
if sys.version_info < (3, 12):
@deprecated(
"Deprecated since Python 3.4; removed in Python 3.12. "
Expand Down
4 changes: 3 additions & 1 deletion stdlib/importlib/abc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ class FileLoader(_bootstrap_external.FileLoader, ResourceLoader, ExecutionLoader
def __init__(self, fullname: str, path: str) -> None: ...
def get_data(self, path: str) -> bytes: ...
def get_filename(self, fullname: str | None = None) -> str: ...
def load_module(self, fullname: str | None = None) -> types.ModuleType: ...
if sys.version_info < (3, 15):
@deprecated("Deprecated since Python 3.10; removed in Python 3.15. Use `exec_module()` instead.")
def load_module(self, fullname: str | None = None) -> types.ModuleType: ...

if sys.version_info < (3, 11):
class ResourceReader(metaclass=ABCMeta):
Expand Down
9 changes: 7 additions & 2 deletions stdlib/importlib/resources/_common.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,22 @@ if sys.version_info >= (3, 11):

Package: TypeAlias = str | types.ModuleType

if sys.version_info >= (3, 12):
if sys.version_info >= (3, 15):
Anchor: TypeAlias = Package

def files(anchor: Anchor | None = None) -> Traversable: ...
elif sys.version_info >= (3, 12):
Anchor: TypeAlias = Package

@deprecated("Deprecated since Python 3.12; removed in Python 3.15.")
def package_to_anchor(
func: Callable[[Anchor | None], Traversable],
) -> Callable[[Anchor | None, Anchor | None], Traversable]: ...

@overload
def files(anchor: Anchor | None = None) -> Traversable: ...
@overload
@deprecated("Deprecated since Python 3.12; will be removed in Python 3.15. Use `anchor` parameter instead.")
@deprecated("Deprecated since Python 3.12; removed in Python 3.15. Use `anchor` parameter instead.")
def files(package: Anchor | None = None) -> Traversable: ...

else:
Expand Down