Skip to content

Commit 9fe9525

Browse files
Sync typeshed (#18747)
Source commit: python/typeshed@0b13c1d
1 parent 27417ba commit 9fe9525

23 files changed

+1159
-833
lines changed

mypy/typeshed/stdlib/_hashlib.pyi

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,26 @@ import sys
22
from _typeshed import ReadableBuffer
33
from collections.abc import Callable
44
from types import ModuleType
5-
from typing import AnyStr, final, overload
5+
from typing import AnyStr, Protocol, final, overload, type_check_only
66
from typing_extensions import Self, TypeAlias
77

8-
_DigestMod: TypeAlias = str | Callable[[], HASH] | ModuleType | None
8+
_DigestMod: TypeAlias = str | Callable[[], _HashObject] | ModuleType | None
99

1010
openssl_md_meth_names: frozenset[str]
1111

12+
@type_check_only
13+
class _HashObject(Protocol):
14+
@property
15+
def digest_size(self) -> int: ...
16+
@property
17+
def block_size(self) -> int: ...
18+
@property
19+
def name(self) -> str: ...
20+
def copy(self) -> Self: ...
21+
def digest(self) -> bytes: ...
22+
def hexdigest(self) -> str: ...
23+
def update(self, obj: ReadableBuffer, /) -> None: ...
24+
1225
class HASH:
1326
@property
1427
def digest_size(self) -> int: ...

mypy/typeshed/stdlib/asyncio/__init__.pyi

Lines changed: 0 additions & 178 deletions
Original file line numberDiff line numberDiff line change
@@ -410,93 +410,6 @@ if sys.platform == "win32":
410410
"WindowsSelectorEventLoopPolicy", # from windows_events
411411
"WindowsProactorEventLoopPolicy", # from windows_events
412412
)
413-
elif sys.version_info >= (3, 10):
414-
__all__ = (
415-
"BaseEventLoop", # from base_events
416-
"Server", # from base_events
417-
"coroutine", # from coroutines
418-
"iscoroutinefunction", # from coroutines
419-
"iscoroutine", # from coroutines
420-
"AbstractEventLoopPolicy", # from events
421-
"AbstractEventLoop", # from events
422-
"AbstractServer", # from events
423-
"Handle", # from events
424-
"TimerHandle", # from events
425-
"get_event_loop_policy", # from events
426-
"set_event_loop_policy", # from events
427-
"get_event_loop", # from events
428-
"set_event_loop", # from events
429-
"new_event_loop", # from events
430-
"get_child_watcher", # from events
431-
"set_child_watcher", # from events
432-
"_set_running_loop", # from events
433-
"get_running_loop", # from events
434-
"_get_running_loop", # from events
435-
"CancelledError", # from exceptions
436-
"InvalidStateError", # from exceptions
437-
"TimeoutError", # from exceptions
438-
"IncompleteReadError", # from exceptions
439-
"LimitOverrunError", # from exceptions
440-
"SendfileNotAvailableError", # from exceptions
441-
"Future", # from futures
442-
"wrap_future", # from futures
443-
"isfuture", # from futures
444-
"Lock", # from locks
445-
"Event", # from locks
446-
"Condition", # from locks
447-
"Semaphore", # from locks
448-
"BoundedSemaphore", # from locks
449-
"BaseProtocol", # from protocols
450-
"Protocol", # from protocols
451-
"DatagramProtocol", # from protocols
452-
"SubprocessProtocol", # from protocols
453-
"BufferedProtocol", # from protocols
454-
"run", # from runners
455-
"Queue", # from queues
456-
"PriorityQueue", # from queues
457-
"LifoQueue", # from queues
458-
"QueueFull", # from queues
459-
"QueueEmpty", # from queues
460-
"StreamReader", # from streams
461-
"StreamWriter", # from streams
462-
"StreamReaderProtocol", # from streams
463-
"open_connection", # from streams
464-
"start_server", # from streams
465-
"create_subprocess_exec", # from subprocess
466-
"create_subprocess_shell", # from subprocess
467-
"Task", # from tasks
468-
"create_task", # from tasks
469-
"FIRST_COMPLETED", # from tasks
470-
"FIRST_EXCEPTION", # from tasks
471-
"ALL_COMPLETED", # from tasks
472-
"wait", # from tasks
473-
"wait_for", # from tasks
474-
"as_completed", # from tasks
475-
"sleep", # from tasks
476-
"gather", # from tasks
477-
"shield", # from tasks
478-
"ensure_future", # from tasks
479-
"run_coroutine_threadsafe", # from tasks
480-
"current_task", # from tasks
481-
"all_tasks", # from tasks
482-
"_register_task", # from tasks
483-
"_unregister_task", # from tasks
484-
"_enter_task", # from tasks
485-
"_leave_task", # from tasks
486-
"to_thread", # from threads
487-
"BaseTransport", # from transports
488-
"ReadTransport", # from transports
489-
"WriteTransport", # from transports
490-
"Transport", # from transports
491-
"DatagramTransport", # from transports
492-
"SubprocessTransport", # from transports
493-
"SelectorEventLoop", # from windows_events
494-
"ProactorEventLoop", # from windows_events
495-
"IocpProactor", # from windows_events
496-
"DefaultEventLoopPolicy", # from windows_events
497-
"WindowsSelectorEventLoopPolicy", # from windows_events
498-
"WindowsProactorEventLoopPolicy", # from windows_events
499-
)
500413
elif sys.version_info >= (3, 9):
501414
__all__ = (
502415
"BaseEventLoop", # from base_events
@@ -1059,97 +972,6 @@ else:
1059972
"ThreadedChildWatcher", # from unix_events
1060973
"DefaultEventLoopPolicy", # from unix_events
1061974
)
1062-
elif sys.version_info >= (3, 10):
1063-
__all__ = (
1064-
"BaseEventLoop", # from base_events
1065-
"Server", # from base_events
1066-
"coroutine", # from coroutines
1067-
"iscoroutinefunction", # from coroutines
1068-
"iscoroutine", # from coroutines
1069-
"AbstractEventLoopPolicy", # from events
1070-
"AbstractEventLoop", # from events
1071-
"AbstractServer", # from events
1072-
"Handle", # from events
1073-
"TimerHandle", # from events
1074-
"get_event_loop_policy", # from events
1075-
"set_event_loop_policy", # from events
1076-
"get_event_loop", # from events
1077-
"set_event_loop", # from events
1078-
"new_event_loop", # from events
1079-
"get_child_watcher", # from events
1080-
"set_child_watcher", # from events
1081-
"_set_running_loop", # from events
1082-
"get_running_loop", # from events
1083-
"_get_running_loop", # from events
1084-
"CancelledError", # from exceptions
1085-
"InvalidStateError", # from exceptions
1086-
"TimeoutError", # from exceptions
1087-
"IncompleteReadError", # from exceptions
1088-
"LimitOverrunError", # from exceptions
1089-
"SendfileNotAvailableError", # from exceptions
1090-
"Future", # from futures
1091-
"wrap_future", # from futures
1092-
"isfuture", # from futures
1093-
"Lock", # from locks
1094-
"Event", # from locks
1095-
"Condition", # from locks
1096-
"Semaphore", # from locks
1097-
"BoundedSemaphore", # from locks
1098-
"BaseProtocol", # from protocols
1099-
"Protocol", # from protocols
1100-
"DatagramProtocol", # from protocols
1101-
"SubprocessProtocol", # from protocols
1102-
"BufferedProtocol", # from protocols
1103-
"run", # from runners
1104-
"Queue", # from queues
1105-
"PriorityQueue", # from queues
1106-
"LifoQueue", # from queues
1107-
"QueueFull", # from queues
1108-
"QueueEmpty", # from queues
1109-
"StreamReader", # from streams
1110-
"StreamWriter", # from streams
1111-
"StreamReaderProtocol", # from streams
1112-
"open_connection", # from streams
1113-
"start_server", # from streams
1114-
"open_unix_connection", # from streams
1115-
"start_unix_server", # from streams
1116-
"create_subprocess_exec", # from subprocess
1117-
"create_subprocess_shell", # from subprocess
1118-
"Task", # from tasks
1119-
"create_task", # from tasks
1120-
"FIRST_COMPLETED", # from tasks
1121-
"FIRST_EXCEPTION", # from tasks
1122-
"ALL_COMPLETED", # from tasks
1123-
"wait", # from tasks
1124-
"wait_for", # from tasks
1125-
"as_completed", # from tasks
1126-
"sleep", # from tasks
1127-
"gather", # from tasks
1128-
"shield", # from tasks
1129-
"ensure_future", # from tasks
1130-
"run_coroutine_threadsafe", # from tasks
1131-
"current_task", # from tasks
1132-
"all_tasks", # from tasks
1133-
"_register_task", # from tasks
1134-
"_unregister_task", # from tasks
1135-
"_enter_task", # from tasks
1136-
"_leave_task", # from tasks
1137-
"to_thread", # from threads
1138-
"BaseTransport", # from transports
1139-
"ReadTransport", # from transports
1140-
"WriteTransport", # from transports
1141-
"Transport", # from transports
1142-
"DatagramTransport", # from transports
1143-
"SubprocessTransport", # from transports
1144-
"SelectorEventLoop", # from unix_events
1145-
"AbstractChildWatcher", # from unix_events
1146-
"SafeChildWatcher", # from unix_events
1147-
"FastChildWatcher", # from unix_events
1148-
"PidfdChildWatcher", # from unix_events
1149-
"MultiLoopChildWatcher", # from unix_events
1150-
"ThreadedChildWatcher", # from unix_events
1151-
"DefaultEventLoopPolicy", # from unix_events
1152-
)
1153975
elif sys.version_info >= (3, 9):
1154976
__all__ = (
1155977
"BaseEventLoop", # from base_events

mypy/typeshed/stdlib/builtins.pyi

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ from _typeshed import (
1010
ConvertibleToFloat,
1111
ConvertibleToInt,
1212
FileDescriptorOrPath,
13-
MaybeNone,
1413
OpenBinaryMode,
1514
OpenBinaryModeReading,
1615
OpenBinaryModeUpdating,
@@ -94,9 +93,14 @@ _SupportsAnextT = TypeVar("_SupportsAnextT", bound=SupportsAnext[Any], covariant
9493
_AwaitableT = TypeVar("_AwaitableT", bound=Awaitable[Any])
9594
_AwaitableT_co = TypeVar("_AwaitableT_co", bound=Awaitable[Any], covariant=True)
9695
_P = ParamSpec("_P")
97-
_StartT = TypeVar("_StartT", covariant=True, default=Any)
98-
_StopT = TypeVar("_StopT", covariant=True, default=Any)
99-
_StepT = TypeVar("_StepT", covariant=True, default=Any)
96+
97+
# Type variables for slice
98+
_StartT_co = TypeVar("_StartT_co", covariant=True, default=Any) # slice -> slice[Any, Any, Any]
99+
_StopT_co = TypeVar("_StopT_co", covariant=True, default=_StartT_co) # slice[A] -> slice[A, A, A]
100+
# NOTE: step could differ from start and stop, (e.g. datetime/timedelta)l
101+
# the default (start|stop) is chosen to cater to the most common case of int/index slices.
102+
# FIXME: https://github.com/python/typing/issues/213 (replace step=start|stop with step=start&stop)
103+
_StepT_co = TypeVar("_StepT_co", covariant=True, default=_StartT_co | _StopT_co) # slice[A,B] -> slice[A, B, A|B]
100104

101105
class object:
102106
__doc__: str | None
@@ -842,23 +846,35 @@ class bool(int):
842846
def __invert__(self) -> int: ...
843847

844848
@final
845-
class slice(Generic[_StartT, _StopT, _StepT]):
849+
class slice(Generic[_StartT_co, _StopT_co, _StepT_co]):
846850
@property
847-
def start(self) -> _StartT: ...
851+
def start(self) -> _StartT_co: ...
848852
@property
849-
def step(self) -> _StepT: ...
853+
def step(self) -> _StepT_co: ...
850854
@property
851-
def stop(self) -> _StopT: ...
852-
@overload
853-
def __new__(cls, stop: int | None, /) -> slice[int | MaybeNone, int | MaybeNone, int | MaybeNone]: ...
855+
def stop(self) -> _StopT_co: ...
856+
# Note: __new__ overloads map `None` to `Any`, since users expect slice(x, None)
857+
# to be compatible with slice(None, x).
858+
# generic slice --------------------------------------------------------------------
854859
@overload
855-
def __new__(
856-
cls, start: int | None, stop: int | None, step: int | None = None, /
857-
) -> slice[int | MaybeNone, int | MaybeNone, int | MaybeNone]: ...
860+
def __new__(cls, start: None, stop: None = None, step: None = None, /) -> slice[Any, Any, Any]: ...
861+
# unary overloads ------------------------------------------------------------------
858862
@overload
859863
def __new__(cls, stop: _T2, /) -> slice[Any, _T2, Any]: ...
864+
# binary overloads -----------------------------------------------------------------
865+
@overload
866+
def __new__(cls, start: _T1, stop: None, step: None = None, /) -> slice[_T1, Any, Any]: ...
867+
@overload
868+
def __new__(cls, start: None, stop: _T2, step: None = None, /) -> slice[Any, _T2, Any]: ...
869+
@overload
870+
def __new__(cls, start: _T1, stop: _T2, step: None = None, /) -> slice[_T1, _T2, Any]: ...
871+
# ternary overloads ----------------------------------------------------------------
872+
@overload
873+
def __new__(cls, start: None, stop: None, step: _T3, /) -> slice[Any, Any, _T3]: ...
874+
@overload
875+
def __new__(cls, start: _T1, stop: None, step: _T3, /) -> slice[_T1, Any, _T3]: ...
860876
@overload
861-
def __new__(cls, start: _T1, stop: _T2, /) -> slice[_T1, _T2, Any]: ...
877+
def __new__(cls, start: None, stop: _T2, step: _T3, /) -> slice[Any, _T2, _T3]: ...
862878
@overload
863879
def __new__(cls, start: _T1, stop: _T2, step: _T3, /) -> slice[_T1, _T2, _T3]: ...
864880
def __eq__(self, value: object, /) -> bool: ...

0 commit comments

Comments
 (0)