Skip to content

Commit 5d15355

Browse files
Remove Python 3.8 exclusive branches from _asyncio, _blake2, _codecs, _contextvars (#13773)
Remove 3.8 exclusive branches from asyncio, _blake2, codecs, contextvars
1 parent ad8ecaf commit 5d15355

4 files changed

Lines changed: 49 additions & 124 deletions

File tree

stdlib/_asyncio.pyi

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@ import sys
22
from asyncio.events import AbstractEventLoop
33
from collections.abc import Awaitable, Callable, Coroutine, Generator
44
from contextvars import Context
5-
from types import FrameType
5+
from types import FrameType, GenericAlias
66
from typing import Any, Literal, TextIO, TypeVar
77
from typing_extensions import Self, TypeAlias
88

9-
if sys.version_info >= (3, 9):
10-
from types import GenericAlias
11-
129
_T = TypeVar("_T")
1310
_T_co = TypeVar("_T_co", covariant=True)
1411
_TaskYieldType: TypeAlias = Future[object] | None
@@ -29,11 +26,7 @@ class Future(Awaitable[_T]):
2926
@property
3027
def _callbacks(self) -> list[tuple[Callable[[Self], Any], Context]]: ...
3128
def add_done_callback(self, fn: Callable[[Self], object], /, *, context: Context | None = None) -> None: ...
32-
if sys.version_info >= (3, 9):
33-
def cancel(self, msg: Any | None = None) -> bool: ...
34-
else:
35-
def cancel(self) -> bool: ...
36-
29+
def cancel(self, msg: Any | None = None) -> bool: ...
3730
def cancelled(self) -> bool: ...
3831
def done(self) -> bool: ...
3932
def result(self) -> _T: ...
@@ -45,15 +38,12 @@ class Future(Awaitable[_T]):
4538
def __await__(self) -> Generator[Any, None, _T]: ...
4639
@property
4740
def _loop(self) -> AbstractEventLoop: ...
48-
if sys.version_info >= (3, 9):
49-
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
41+
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
5042

5143
if sys.version_info >= (3, 12):
5244
_TaskCompatibleCoro: TypeAlias = Coroutine[Any, Any, _T_co]
53-
elif sys.version_info >= (3, 9):
54-
_TaskCompatibleCoro: TypeAlias = Generator[_TaskYieldType, None, _T_co] | Coroutine[Any, Any, _T_co]
5545
else:
56-
_TaskCompatibleCoro: TypeAlias = Generator[_TaskYieldType, None, _T_co] | Awaitable[_T_co]
46+
_TaskCompatibleCoro: TypeAlias = Generator[_TaskYieldType, None, _T_co] | Coroutine[Any, Any, _T_co]
5747

5848
# mypy and pyright complain that a subclass of an invariant class shouldn't be covariant.
5949
# While this is true in general, here it's sort-of okay to have a covariant subclass,
@@ -99,13 +89,8 @@ class Task(Future[_T_co]): # type: ignore[type-var] # pyright: ignore[reportIn
9989
if sys.version_info >= (3, 11):
10090
def cancelling(self) -> int: ...
10191
def uncancel(self) -> int: ...
102-
if sys.version_info < (3, 9):
103-
@classmethod
104-
def current_task(cls, loop: AbstractEventLoop | None = None) -> Task[Any] | None: ...
105-
@classmethod
106-
def all_tasks(cls, loop: AbstractEventLoop | None = None) -> set[Task[Any]]: ...
107-
if sys.version_info >= (3, 9):
108-
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
92+
93+
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
10994

11095
def get_event_loop() -> AbstractEventLoop: ...
11196
def get_running_loop() -> AbstractEventLoop: ...

stdlib/_blake2.pyi

Lines changed: 36 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import sys
21
from _typeshed import ReadableBuffer
32
from typing import ClassVar, final
43
from typing_extensions import Self
@@ -21,44 +20,24 @@ class blake2b:
2120
block_size: int
2221
digest_size: int
2322
name: str
24-
if sys.version_info >= (3, 9):
25-
def __new__(
26-
cls,
27-
data: ReadableBuffer = b"",
28-
/,
29-
*,
30-
digest_size: int = 64,
31-
key: ReadableBuffer = b"",
32-
salt: ReadableBuffer = b"",
33-
person: ReadableBuffer = b"",
34-
fanout: int = 1,
35-
depth: int = 1,
36-
leaf_size: int = 0,
37-
node_offset: int = 0,
38-
node_depth: int = 0,
39-
inner_size: int = 0,
40-
last_node: bool = False,
41-
usedforsecurity: bool = True,
42-
) -> Self: ...
43-
else:
44-
def __new__(
45-
cls,
46-
data: ReadableBuffer = b"",
47-
/,
48-
*,
49-
digest_size: int = 64,
50-
key: ReadableBuffer = b"",
51-
salt: ReadableBuffer = b"",
52-
person: ReadableBuffer = b"",
53-
fanout: int = 1,
54-
depth: int = 1,
55-
leaf_size: int = 0,
56-
node_offset: int = 0,
57-
node_depth: int = 0,
58-
inner_size: int = 0,
59-
last_node: bool = False,
60-
) -> Self: ...
61-
23+
def __new__(
24+
cls,
25+
data: ReadableBuffer = b"",
26+
/,
27+
*,
28+
digest_size: int = 64,
29+
key: ReadableBuffer = b"",
30+
salt: ReadableBuffer = b"",
31+
person: ReadableBuffer = b"",
32+
fanout: int = 1,
33+
depth: int = 1,
34+
leaf_size: int = 0,
35+
node_offset: int = 0,
36+
node_depth: int = 0,
37+
inner_size: int = 0,
38+
last_node: bool = False,
39+
usedforsecurity: bool = True,
40+
) -> Self: ...
6241
def copy(self) -> Self: ...
6342
def digest(self) -> bytes: ...
6443
def hexdigest(self) -> str: ...
@@ -73,44 +52,24 @@ class blake2s:
7352
block_size: int
7453
digest_size: int
7554
name: str
76-
if sys.version_info >= (3, 9):
77-
def __new__(
78-
cls,
79-
data: ReadableBuffer = b"",
80-
/,
81-
*,
82-
digest_size: int = 32,
83-
key: ReadableBuffer = b"",
84-
salt: ReadableBuffer = b"",
85-
person: ReadableBuffer = b"",
86-
fanout: int = 1,
87-
depth: int = 1,
88-
leaf_size: int = 0,
89-
node_offset: int = 0,
90-
node_depth: int = 0,
91-
inner_size: int = 0,
92-
last_node: bool = False,
93-
usedforsecurity: bool = True,
94-
) -> Self: ...
95-
else:
96-
def __new__(
97-
cls,
98-
data: ReadableBuffer = b"",
99-
/,
100-
*,
101-
digest_size: int = 32,
102-
key: ReadableBuffer = b"",
103-
salt: ReadableBuffer = b"",
104-
person: ReadableBuffer = b"",
105-
fanout: int = 1,
106-
depth: int = 1,
107-
leaf_size: int = 0,
108-
node_offset: int = 0,
109-
node_depth: int = 0,
110-
inner_size: int = 0,
111-
last_node: bool = False,
112-
) -> Self: ...
113-
55+
def __new__(
56+
cls,
57+
data: ReadableBuffer = b"",
58+
/,
59+
*,
60+
digest_size: int = 32,
61+
key: ReadableBuffer = b"",
62+
salt: ReadableBuffer = b"",
63+
person: ReadableBuffer = b"",
64+
fanout: int = 1,
65+
depth: int = 1,
66+
leaf_size: int = 0,
67+
node_offset: int = 0,
68+
node_depth: int = 0,
69+
inner_size: int = 0,
70+
last_node: bool = False,
71+
usedforsecurity: bool = True,
72+
) -> Self: ...
11473
def copy(self) -> Self: ...
11574
def digest(self) -> bytes: ...
11675
def hexdigest(self) -> str: ...

stdlib/_codecs.pyi

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,26 +81,12 @@ def escape_decode(data: str | ReadableBuffer, errors: str | None = None, /) -> t
8181
def escape_encode(data: bytes, errors: str | None = None, /) -> tuple[bytes, int]: ...
8282
def latin_1_decode(data: ReadableBuffer, errors: str | None = None, /) -> tuple[str, int]: ...
8383
def latin_1_encode(str: str, errors: str | None = None, /) -> tuple[bytes, int]: ...
84-
85-
if sys.version_info >= (3, 9):
86-
def raw_unicode_escape_decode(
87-
data: str | ReadableBuffer, errors: str | None = None, final: bool = True, /
88-
) -> tuple[str, int]: ...
89-
90-
else:
91-
def raw_unicode_escape_decode(data: str | ReadableBuffer, errors: str | None = None, /) -> tuple[str, int]: ...
92-
84+
def raw_unicode_escape_decode(
85+
data: str | ReadableBuffer, errors: str | None = None, final: bool = True, /
86+
) -> tuple[str, int]: ...
9387
def raw_unicode_escape_encode(str: str, errors: str | None = None, /) -> tuple[bytes, int]: ...
9488
def readbuffer_encode(data: str | ReadableBuffer, errors: str | None = None, /) -> tuple[bytes, int]: ...
95-
96-
if sys.version_info >= (3, 9):
97-
def unicode_escape_decode(
98-
data: str | ReadableBuffer, errors: str | None = None, final: bool = True, /
99-
) -> tuple[str, int]: ...
100-
101-
else:
102-
def unicode_escape_decode(data: str | ReadableBuffer, errors: str | None = None, /) -> tuple[str, int]: ...
103-
89+
def unicode_escape_decode(data: str | ReadableBuffer, errors: str | None = None, final: bool = True, /) -> tuple[str, int]: ...
10490
def unicode_escape_encode(str: str, errors: str | None = None, /) -> tuple[bytes, int]: ...
10591
def utf_16_be_decode(data: ReadableBuffer, errors: str | None = None, final: bool = False, /) -> tuple[str, int]: ...
10692
def utf_16_be_encode(str: str, errors: str | None = None, /) -> tuple[bytes, int]: ...

stdlib/_contextvars.pyi

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import sys
21
from collections.abc import Callable, Iterator, Mapping
2+
from types import GenericAlias
33
from typing import Any, ClassVar, Generic, TypeVar, final, overload
44
from typing_extensions import ParamSpec, Self
55

6-
if sys.version_info >= (3, 9):
7-
from types import GenericAlias
8-
96
_T = TypeVar("_T")
107
_D = TypeVar("_D")
118
_P = ParamSpec("_P")
@@ -27,8 +24,7 @@ class ContextVar(Generic[_T]):
2724
def get(self, default: _D, /) -> _D | _T: ...
2825
def set(self, value: _T, /) -> Token[_T]: ...
2926
def reset(self, token: Token[_T], /) -> None: ...
30-
if sys.version_info >= (3, 9):
31-
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
27+
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
3228

3329
@final
3430
class Token(Generic[_T]):
@@ -38,8 +34,7 @@ class Token(Generic[_T]):
3834
def old_value(self) -> Any: ... # returns either _T or MISSING, but that's hard to express
3935
MISSING: ClassVar[object]
4036
__hash__: ClassVar[None] # type: ignore[assignment]
41-
if sys.version_info >= (3, 9):
42-
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
37+
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
4338

4439
def copy_context() -> Context: ...
4540

0 commit comments

Comments
 (0)