Skip to content

Commit 2e0d912

Browse files
author
mypybot
committed
Sync typeshed
Source commit: python/typeshed@d262beb
1 parent b59878e commit 2e0d912

14 files changed

+447
-213
lines changed

mypy/typeshed/stdlib/VERSIONS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ _curses: 3.0-
3434
_decimal: 3.3-
3535
_dummy_thread: 3.0-3.8
3636
_dummy_threading: 3.0-3.8
37+
_frozen_importlib: 3.0-
38+
_frozen_importlib_external: 3.5-
3739
_heapq: 3.0-
3840
_imp: 3.0-
3941
_interpchannels: 3.13-
@@ -161,6 +163,8 @@ imghdr: 3.0-3.12
161163
imp: 3.0-3.11
162164
importlib: 3.0-
163165
importlib._abc: 3.10-
166+
importlib._bootstrap: 3.0-
167+
importlib._bootstrap_external: 3.5-
164168
importlib.metadata: 3.8-
165169
importlib.metadata._meta: 3.10-
166170
importlib.metadata.diagnose: 3.13-

mypy/typeshed/stdlib/_ctypes.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,11 @@ class Array(_CData, Generic[_CT]):
171171
def _type_(self) -> type[_CT]: ...
172172
@_type_.setter
173173
def _type_(self, value: type[_CT]) -> None: ...
174-
raw: bytes # Note: only available if _CT == c_char
174+
# Note: only available if _CT == c_char
175+
@property
176+
def raw(self) -> bytes: ...
177+
@raw.setter
178+
def raw(self, value: ReadableBuffer) -> None: ...
175179
value: Any # Note: bytes if _CT == c_char, str if _CT == c_wchar, unavailable otherwise
176180
# TODO These methods cannot be annotated correctly at the moment.
177181
# All of these "Any"s stand for the array's element type, but it's not possible to use _CT
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import importlib.abc
2+
import importlib.machinery
3+
import sys
4+
import types
5+
from _typeshed.importlib import LoaderProtocol
6+
from collections.abc import Mapping, Sequence
7+
from types import ModuleType
8+
from typing import Any
9+
10+
# Signature of `builtins.__import__` should be kept identical to `importlib.__import__`
11+
def __import__(
12+
name: str,
13+
globals: Mapping[str, object] | None = None,
14+
locals: Mapping[str, object] | None = None,
15+
fromlist: Sequence[str] = (),
16+
level: int = 0,
17+
) -> ModuleType: ...
18+
def spec_from_loader(
19+
name: str, loader: LoaderProtocol | None, *, origin: str | None = None, is_package: bool | None = None
20+
) -> importlib.machinery.ModuleSpec | None: ...
21+
def module_from_spec(spec: importlib.machinery.ModuleSpec) -> types.ModuleType: ...
22+
def _init_module_attrs(
23+
spec: importlib.machinery.ModuleSpec, module: types.ModuleType, *, override: bool = False
24+
) -> types.ModuleType: ...
25+
26+
class ModuleSpec:
27+
def __init__(
28+
self,
29+
name: str,
30+
loader: importlib.abc.Loader | None,
31+
*,
32+
origin: str | None = None,
33+
loader_state: Any = None,
34+
is_package: bool | None = None,
35+
) -> None: ...
36+
name: str
37+
loader: importlib.abc.Loader | None
38+
origin: str | None
39+
submodule_search_locations: list[str] | None
40+
loader_state: Any
41+
cached: str | None
42+
@property
43+
def parent(self) -> str | None: ...
44+
has_location: bool
45+
def __eq__(self, other: object) -> bool: ...
46+
47+
class BuiltinImporter(importlib.abc.MetaPathFinder, importlib.abc.InspectLoader):
48+
# MetaPathFinder
49+
if sys.version_info < (3, 12):
50+
@classmethod
51+
def find_module(cls, fullname: str, path: Sequence[str] | None = None) -> importlib.abc.Loader | None: ...
52+
53+
@classmethod
54+
def find_spec(
55+
cls, fullname: str, path: Sequence[str] | None = None, target: types.ModuleType | None = None
56+
) -> ModuleSpec | None: ...
57+
# InspectLoader
58+
@classmethod
59+
def is_package(cls, fullname: str) -> bool: ...
60+
@classmethod
61+
def load_module(cls, fullname: str) -> types.ModuleType: ...
62+
@classmethod
63+
def get_code(cls, fullname: str) -> None: ...
64+
@classmethod
65+
def get_source(cls, fullname: str) -> None: ...
66+
# Loader
67+
if sys.version_info < (3, 12):
68+
@staticmethod
69+
def module_repr(module: types.ModuleType) -> str: ...
70+
if sys.version_info >= (3, 10):
71+
@staticmethod
72+
def create_module(spec: ModuleSpec) -> types.ModuleType | None: ...
73+
@staticmethod
74+
def exec_module(module: types.ModuleType) -> None: ...
75+
else:
76+
@classmethod
77+
def create_module(cls, spec: ModuleSpec) -> types.ModuleType | None: ...
78+
@classmethod
79+
def exec_module(cls, module: types.ModuleType) -> None: ...
80+
81+
class FrozenImporter(importlib.abc.MetaPathFinder, importlib.abc.InspectLoader):
82+
# MetaPathFinder
83+
if sys.version_info < (3, 12):
84+
@classmethod
85+
def find_module(cls, fullname: str, path: Sequence[str] | None = None) -> importlib.abc.Loader | None: ...
86+
87+
@classmethod
88+
def find_spec(
89+
cls, fullname: str, path: Sequence[str] | None = None, target: types.ModuleType | None = None
90+
) -> ModuleSpec | None: ...
91+
# InspectLoader
92+
@classmethod
93+
def is_package(cls, fullname: str) -> bool: ...
94+
@classmethod
95+
def load_module(cls, fullname: str) -> types.ModuleType: ...
96+
@classmethod
97+
def get_code(cls, fullname: str) -> None: ...
98+
@classmethod
99+
def get_source(cls, fullname: str) -> None: ...
100+
# Loader
101+
if sys.version_info < (3, 12):
102+
@staticmethod
103+
def module_repr(m: types.ModuleType) -> str: ...
104+
if sys.version_info >= (3, 10):
105+
@staticmethod
106+
def create_module(spec: ModuleSpec) -> types.ModuleType | None: ...
107+
else:
108+
@classmethod
109+
def create_module(cls, spec: ModuleSpec) -> types.ModuleType | None: ...
110+
111+
@staticmethod
112+
def exec_module(module: types.ModuleType) -> None: ...
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
import _ast
2+
import _io
3+
import importlib.abc
4+
import importlib.machinery
5+
import sys
6+
import types
7+
from _typeshed import ReadableBuffer, StrOrBytesPath, StrPath
8+
from _typeshed.importlib import LoaderProtocol
9+
from collections.abc import Callable, Iterable, Iterator, Mapping, MutableSequence, Sequence
10+
from importlib.machinery import ModuleSpec
11+
from importlib.metadata import DistributionFinder, PathDistribution
12+
from typing import Any, Literal
13+
from typing_extensions import Self, deprecated
14+
15+
if sys.version_info >= (3, 10):
16+
import importlib.readers
17+
18+
if sys.platform == "win32":
19+
path_separators: Literal["\\/"]
20+
path_sep: Literal["\\"]
21+
path_sep_tuple: tuple[Literal["\\"], Literal["/"]]
22+
else:
23+
path_separators: Literal["/"]
24+
path_sep: Literal["/"]
25+
path_sep_tuple: tuple[Literal["/"]]
26+
27+
MAGIC_NUMBER: bytes
28+
29+
def cache_from_source(path: str, debug_override: bool | None = None, *, optimization: Any | None = None) -> str: ...
30+
def source_from_cache(path: str) -> str: ...
31+
def decode_source(source_bytes: ReadableBuffer) -> str: ...
32+
def spec_from_file_location(
33+
name: str,
34+
location: StrOrBytesPath | None = None,
35+
*,
36+
loader: LoaderProtocol | None = None,
37+
submodule_search_locations: list[str] | None = ...,
38+
) -> importlib.machinery.ModuleSpec | None: ...
39+
40+
class WindowsRegistryFinder(importlib.abc.MetaPathFinder):
41+
if sys.version_info < (3, 12):
42+
@classmethod
43+
def find_module(cls, fullname: str, path: Sequence[str] | None = None) -> importlib.abc.Loader | None: ...
44+
45+
@classmethod
46+
def find_spec(
47+
cls, fullname: str, path: Sequence[str] | None = None, target: types.ModuleType | None = None
48+
) -> ModuleSpec | None: ...
49+
50+
class PathFinder(importlib.abc.MetaPathFinder):
51+
if sys.version_info >= (3, 10):
52+
@staticmethod
53+
def invalidate_caches() -> None: ...
54+
else:
55+
@classmethod
56+
def invalidate_caches(cls) -> None: ...
57+
if sys.version_info >= (3, 10):
58+
@staticmethod
59+
def find_distributions(context: DistributionFinder.Context = ...) -> Iterable[PathDistribution]: ...
60+
else:
61+
@classmethod
62+
def find_distributions(cls, context: DistributionFinder.Context = ...) -> Iterable[PathDistribution]: ...
63+
64+
@classmethod
65+
def find_spec(
66+
cls, fullname: str, path: Sequence[str] | None = None, target: types.ModuleType | None = None
67+
) -> ModuleSpec | None: ...
68+
if sys.version_info < (3, 12):
69+
@classmethod
70+
def find_module(cls, fullname: str, path: Sequence[str] | None = None) -> importlib.abc.Loader | None: ...
71+
72+
SOURCE_SUFFIXES: list[str]
73+
DEBUG_BYTECODE_SUFFIXES: list[str]
74+
OPTIMIZED_BYTECODE_SUFFIXES: list[str]
75+
BYTECODE_SUFFIXES: list[str]
76+
EXTENSION_SUFFIXES: list[str]
77+
78+
class FileFinder(importlib.abc.PathEntryFinder):
79+
path: str
80+
def __init__(self, path: str, *loader_details: tuple[type[importlib.abc.Loader], list[str]]) -> None: ...
81+
@classmethod
82+
def path_hook(
83+
cls, *loader_details: tuple[type[importlib.abc.Loader], list[str]]
84+
) -> Callable[[str], importlib.abc.PathEntryFinder]: ...
85+
86+
class _LoaderBasics:
87+
def is_package(self, fullname: str) -> bool: ...
88+
def create_module(self, spec: ModuleSpec) -> types.ModuleType | None: ...
89+
def exec_module(self, module: types.ModuleType) -> None: ...
90+
def load_module(self, fullname: str) -> types.ModuleType: ...
91+
92+
class SourceLoader(_LoaderBasics):
93+
def path_mtime(self, path: str) -> float: ...
94+
def set_data(self, path: str, data: bytes) -> None: ...
95+
def get_source(self, fullname: str) -> str | None: ...
96+
def path_stats(self, path: str) -> Mapping[str, Any]: ...
97+
def source_to_code(
98+
self, data: ReadableBuffer | str | _ast.Module | _ast.Expression | _ast.Interactive, path: ReadableBuffer | StrPath
99+
) -> types.CodeType: ...
100+
def get_code(self, fullname: str) -> types.CodeType | None: ...
101+
102+
class FileLoader:
103+
name: str
104+
path: str
105+
def __init__(self, fullname: str, path: str) -> None: ...
106+
def get_data(self, path: str) -> bytes: ...
107+
def get_filename(self, name: str | None = None) -> str: ...
108+
def load_module(self, name: str | None = None) -> types.ModuleType: ...
109+
if sys.version_info >= (3, 10):
110+
def get_resource_reader(self, module: types.ModuleType) -> importlib.readers.FileReader: ...
111+
else:
112+
def get_resource_reader(self, module: types.ModuleType) -> Self | None: ...
113+
def open_resource(self, resource: str) -> _io.FileIO: ...
114+
def resource_path(self, resource: str) -> str: ...
115+
def is_resource(self, name: str) -> bool: ...
116+
def contents(self) -> Iterator[str]: ...
117+
118+
class SourceFileLoader(importlib.abc.FileLoader, FileLoader, importlib.abc.SourceLoader, SourceLoader): # type: ignore[misc] # incompatible method arguments in base classes
119+
def set_data(self, path: str, data: ReadableBuffer, *, _mode: int = 0o666) -> None: ...
120+
def path_stats(self, path: str) -> Mapping[str, Any]: ...
121+
122+
class SourcelessFileLoader(importlib.abc.FileLoader, FileLoader, _LoaderBasics):
123+
def get_code(self, fullname: str) -> types.CodeType | None: ...
124+
def get_source(self, fullname: str) -> None: ...
125+
126+
class ExtensionFileLoader(FileLoader, _LoaderBasics, importlib.abc.ExecutionLoader):
127+
def __init__(self, name: str, path: str) -> None: ...
128+
def get_filename(self, name: str | None = None) -> str: ...
129+
def get_source(self, fullname: str) -> None: ...
130+
def create_module(self, spec: ModuleSpec) -> types.ModuleType: ...
131+
def exec_module(self, module: types.ModuleType) -> None: ...
132+
def get_code(self, fullname: str) -> None: ...
133+
def __eq__(self, other: object) -> bool: ...
134+
def __hash__(self) -> int: ...
135+
136+
if sys.version_info >= (3, 11):
137+
class NamespaceLoader(importlib.abc.InspectLoader):
138+
def __init__(
139+
self, name: str, path: MutableSequence[str], path_finder: Callable[[str, tuple[str, ...]], ModuleSpec]
140+
) -> None: ...
141+
def is_package(self, fullname: str) -> Literal[True]: ...
142+
def get_source(self, fullname: str) -> Literal[""]: ...
143+
def get_code(self, fullname: str) -> types.CodeType: ...
144+
def create_module(self, spec: ModuleSpec) -> None: ...
145+
def exec_module(self, module: types.ModuleType) -> None: ...
146+
@deprecated("load_module() is deprecated; use exec_module() instead")
147+
def load_module(self, fullname: str) -> types.ModuleType: ...
148+
def get_resource_reader(self, module: types.ModuleType) -> importlib.readers.NamespaceReader: ...
149+
if sys.version_info < (3, 12):
150+
@staticmethod
151+
@deprecated("module_repr() is deprecated, and has been removed in Python 3.12")
152+
def module_repr(module: types.ModuleType) -> str: ...
153+
154+
_NamespaceLoader = NamespaceLoader
155+
else:
156+
class _NamespaceLoader:
157+
def __init__(
158+
self, name: str, path: MutableSequence[str], path_finder: Callable[[str, tuple[str, ...]], ModuleSpec]
159+
) -> None: ...
160+
def is_package(self, fullname: str) -> Literal[True]: ...
161+
def get_source(self, fullname: str) -> Literal[""]: ...
162+
def get_code(self, fullname: str) -> types.CodeType: ...
163+
def create_module(self, spec: ModuleSpec) -> None: ...
164+
def exec_module(self, module: types.ModuleType) -> None: ...
165+
@deprecated("load_module() is deprecated; use exec_module() instead")
166+
def load_module(self, fullname: str) -> types.ModuleType: ...
167+
if sys.version_info >= (3, 10):
168+
@staticmethod
169+
@deprecated("module_repr() is deprecated, and has been removed in Python 3.12")
170+
def module_repr(module: types.ModuleType) -> str: ...
171+
def get_resource_reader(self, module: types.ModuleType) -> importlib.readers.NamespaceReader: ...
172+
else:
173+
@classmethod
174+
@deprecated("module_repr() is deprecated, and has been removed in Python 3.12")
175+
def module_repr(cls, module: types.ModuleType) -> str: ...
176+
177+
if sys.version_info >= (3, 13):
178+
class AppleFrameworkLoader(ExtensionFileLoader, importlib.abc.ExecutionLoader): ...

mypy/typeshed/stdlib/_ssl.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class _SSLContext:
105105
if sys.version_info >= (3, 13):
106106
def set_psk_client_callback(self, callback: Callable[[str | None], tuple[str | None, bytes]] | None) -> None: ...
107107
def set_psk_server_callback(
108-
self, callback: Callable[[str | None], tuple[str | None, bytes]] | None, identity_hint: str | None = None
108+
self, callback: Callable[[str | None], bytes] | None, identity_hint: str | None = None
109109
) -> None: ...
110110

111111
@final

0 commit comments

Comments
 (0)