Skip to content

Sync typeshed #12982

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 8, 2022
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
7 changes: 6 additions & 1 deletion mypy/typeshed/stdlib/@python2/ssl.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,12 @@ class SSLContext:
def load_verify_locations(
self, cafile: StrPath | None = ..., capath: StrPath | None = ..., cadata: Text | bytes | None = ...
) -> None: ...
def get_ca_certs(self, binary_form: bool = ...) -> list[_PeerCertRetDictType] | list[bytes]: ...
@overload
def get_ca_certs(self, binary_form: Literal[False] = ...) -> list[_PeerCertRetDictType]: ...
@overload
def get_ca_certs(self, binary_form: Literal[True]) -> list[bytes]: ...
@overload
def get_ca_certs(self, binary_form: bool = ...) -> Any: ...
def set_default_verify_paths(self) -> None: ...
def set_ciphers(self, __cipherlist: str) -> None: ...
def set_alpn_protocols(self, alpn_protocols: Iterable[str]) -> None: ...
Expand Down
1 change: 1 addition & 0 deletions mypy/typeshed/stdlib/VERSIONS
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ asyncio.runners: 3.7-
asyncio.staggered: 3.8-
asyncio.taskgroups: 3.11-
asyncio.threads: 3.9-
asyncio.timeouts: 3.11-
asyncio.trsock: 3.8-
asyncore: 2.7-
atexit: 2.7-
Expand Down
40 changes: 14 additions & 26 deletions mypy/typeshed/stdlib/__future__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,18 @@ if sys.version_info >= (3, 7):

all_feature_names: list[str] # undocumented

__all__ = [
"all_feature_names",
"absolute_import",
"division",
"generators",
"nested_scopes",
"print_function",
"unicode_literals",
"with_statement",
"barry_as_FLUFL",
"generator_stop",
]

if sys.version_info >= (3, 7):
__all__ = [
"all_feature_names",
"absolute_import",
"division",
"generators",
"nested_scopes",
"print_function",
"unicode_literals",
"with_statement",
"barry_as_FLUFL",
"generator_stop",
"annotations",
]
else:
__all__ = [
"all_feature_names",
"absolute_import",
"division",
"generators",
"nested_scopes",
"print_function",
"unicode_literals",
"with_statement",
"barry_as_FLUFL",
"generator_stop",
]
__all__ += ["annotations"]
2 changes: 2 additions & 0 deletions mypy/typeshed/stdlib/_ast.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@ class Tuple(expr):
__match_args__ = ("elts", "ctx")
elts: list[expr]
ctx: expr_context
if sys.version_info >= (3, 9):
dims: list[expr]

class expr_context(AST): ...

Expand Down
63 changes: 56 additions & 7 deletions mypy/typeshed/stdlib/_codecs.pyi
Original file line number Diff line number Diff line change
@@ -1,22 +1,71 @@
import codecs
import sys
from collections.abc import Callable
from typing import Any
from typing_extensions import TypeAlias
from typing import overload
from typing_extensions import Literal, TypeAlias

# This type is not exposed; it is defined in unicodeobject.c
class _EncodingMap:
def size(self) -> int: ...

_MapT: TypeAlias = dict[int, int] | _EncodingMap
_Handler: TypeAlias = Callable[[Exception], tuple[str, int]]
_Handler: TypeAlias = Callable[[UnicodeError], tuple[str | bytes, int]]
_SearchFunction: TypeAlias = Callable[[str], codecs.CodecInfo | None]

def register(__search_function: _SearchFunction) -> None: ...

if sys.version_info >= (3, 10):
def unregister(__search_function: _SearchFunction) -> None: ...

def register(__search_function: Callable[[str], Any]) -> None: ...
def register_error(__errors: str, __handler: _Handler) -> None: ...
def lookup(__encoding: str) -> codecs.CodecInfo: ...
def lookup_error(__name: str) -> _Handler: ...
def decode(obj: Any, encoding: str = ..., errors: str | None = ...) -> Any: ...
def encode(obj: Any, encoding: str = ..., errors: str | None = ...) -> Any: ...

# The type ignore on `encode` and `decode` is to avoid issues with overlapping overloads, for more details, see #300
# https://docs.python.org/3/library/codecs.html#binary-transforms
_BytesToBytesEncoding: TypeAlias = Literal[
"base64",
"base_64",
"base64_codec",
"bz2",
"bz2_codec",
"hex",
"hex_codec",
"quopri",
"quotedprintable",
"quoted_printable",
"quopri_codec",
"uu",
"uu_codec",
"zip",
"zlib",
"zlib_codec",
]
# https://docs.python.org/3/library/codecs.html#text-transforms
_StrToStrEncoding: TypeAlias = Literal["rot13", "rot_13"]

@overload
def encode(obj: bytes, encoding: _BytesToBytesEncoding, errors: str = ...) -> bytes: ...
@overload
def encode(obj: str, encoding: _StrToStrEncoding, errors: str = ...) -> str: ... # type: ignore[misc]
@overload
def encode(obj: str, encoding: str = ..., errors: str = ...) -> bytes: ...
@overload
def decode(obj: bytes, encoding: _BytesToBytesEncoding, errors: str = ...) -> bytes: ... # type: ignore[misc]
@overload
def decode(obj: str, encoding: _StrToStrEncoding, errors: str = ...) -> str: ...

# these are documented as text encodings but in practice they also accept str as input
@overload
def decode(
obj: str, encoding: Literal["unicode_escape", "unicode-escape", "raw_unicode_escape", "raw-unicode-escape"], errors: str = ...
) -> str: ...

# hex is officially documented as a bytes to bytes encoding, but it appears to also work with str
@overload
def decode(obj: str, encoding: Literal["hex", "hex_codec"], errors: str = ...) -> bytes: ...
@overload
def decode(obj: bytes, encoding: str = ..., errors: str = ...) -> str: ...
def lookup(__encoding: str) -> codecs.CodecInfo: ...
def charmap_build(__map: str) -> _MapT: ...
def ascii_decode(__data: bytes, __errors: str | None = ...) -> tuple[str, int]: ...
def ascii_encode(__str: str, __errors: str | None = ...) -> tuple[bytes, int]: ...
Expand Down
10 changes: 10 additions & 0 deletions mypy/typeshed/stdlib/_dummy_thread.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import sys
from collections.abc import Callable
from types import TracebackType
from typing import Any, NoReturn

__all__ = ["error", "start_new_thread", "exit", "get_ident", "allocate_lock", "interrupt_main", "LockType"]

if sys.version_info >= (3, 7):
__all__ += ["RLock"]

TIMEOUT_MAX: int
error = RuntimeError

Expand All @@ -20,4 +26,8 @@ class LockType:
def release(self) -> bool: ...
def locked(self) -> bool: ...

if sys.version_info >= (3, 7):
class RLock(LockType):
def release(self) -> None: ... # type: ignore[override]

def interrupt_main() -> None: ...
74 changes: 25 additions & 49 deletions mypy/typeshed/stdlib/_dummy_threading.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,56 +10,32 @@ _TF: TypeAlias = Callable[[FrameType, str, Any], Callable[..., Any] | None]
_PF: TypeAlias = Callable[[FrameType, str, Any], None]
_T = TypeVar("_T")

__all__ = [
"get_ident",
"active_count",
"Condition",
"current_thread",
"enumerate",
"main_thread",
"TIMEOUT_MAX",
"Event",
"Lock",
"RLock",
"Semaphore",
"BoundedSemaphore",
"Thread",
"Barrier",
"BrokenBarrierError",
"Timer",
"ThreadError",
"setprofile",
"settrace",
"local",
"stack_size",
]

if sys.version_info >= (3, 8):
__all__ = [
"get_ident",
"active_count",
"Condition",
"current_thread",
"enumerate",
"main_thread",
"TIMEOUT_MAX",
"Event",
"Lock",
"RLock",
"Semaphore",
"BoundedSemaphore",
"Thread",
"Barrier",
"BrokenBarrierError",
"Timer",
"ThreadError",
"setprofile",
"settrace",
"local",
"stack_size",
"excepthook",
"ExceptHookArgs",
]
else:
__all__ = [
"get_ident",
"active_count",
"Condition",
"current_thread",
"enumerate",
"main_thread",
"TIMEOUT_MAX",
"Event",
"Lock",
"RLock",
"Semaphore",
"BoundedSemaphore",
"Thread",
"Barrier",
"BrokenBarrierError",
"Timer",
"ThreadError",
"setprofile",
"settrace",
"local",
"stack_size",
]
__all__ += ["ExceptHookArgs", "excepthook"]

def active_count() -> int: ...
def current_thread() -> Thread: ...
Expand Down
10 changes: 9 additions & 1 deletion mypy/typeshed/stdlib/_imp.pyi
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
import sys
import types
from _typeshed import ReadableBuffer
from importlib.machinery import ModuleSpec
from typing import Any

if sys.version_info >= (3, 7):
check_hash_based_pycs: str
def source_hash(key: int, source: ReadableBuffer) -> bytes: ...

def create_builtin(__spec: ModuleSpec) -> types.ModuleType: ...
def create_dynamic(__spec: ModuleSpec, __file: Any = ...) -> types.ModuleType: ...
def acquire_lock() -> None: ...
def exec_builtin(__mod: types.ModuleType) -> int: ...
def exec_dynamic(__mod: types.ModuleType) -> int: ...
def extension_suffixes() -> list[str]: ...
def get_frozen_object(__name: str) -> types.CodeType: ...
def init_frozen(__name: str) -> types.ModuleType: ...
def is_builtin(__name: str) -> int: ...
def is_frozen(__name: str) -> bool: ...
def is_frozen_package(__name: str) -> bool: ...
def lock_held() -> bool: ...
def release_lock() -> None: ...

if sys.version_info >= (3, 11):
def find_frozen(__name: str, *, withdata: bool = ...) -> tuple[memoryview | None, bool, str | None] | None: ...
def get_frozen_object(__name: str, __data: ReadableBuffer | None = ...) -> types.CodeType: ...

else:
def get_frozen_object(__name: str) -> types.CodeType: ...
Loading