Skip to content

Commit e613fc4

Browse files
authored
Delete python 2 branches from third-party stubs (#7741)
Since #7703, we no longer have third-party stubs that support Python 2, so code like `if sys.version_info >= (3, 0)` can be simplified.
1 parent 002c8e2 commit e613fc4

File tree

21 files changed

+40
-203
lines changed

21 files changed

+40
-203
lines changed

stubs/PyMySQL/pymysql/__init__.pyi

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import sys
2-
31
from .connections import Connection as Connection
42
from .constants import FIELD_TYPE as FIELD_TYPE
53
from .converters import escape_dict as escape_dict, escape_sequence as escape_sequence, escape_string as escape_string
@@ -43,12 +41,7 @@ TIMESTAMP: DBAPISet
4341
DATETIME: DBAPISet
4442
ROWID: DBAPISet
4543

46-
if sys.version_info >= (3, 0):
47-
def Binary(x) -> bytes: ...
48-
49-
else:
50-
def Binary(x) -> bytearray: ...
51-
44+
def Binary(x) -> bytes: ...
5245
def get_client_info() -> str: ...
5346

5447
__version__: str

stubs/boto/boto/compat.pyi

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,8 @@
1-
import sys
1+
from base64 import encodebytes as encodebytes
22
from typing import Any
33

4-
if sys.version_info >= (3,):
5-
from base64 import encodebytes as encodebytes
6-
else:
7-
from base64 import encodestring
8-
9-
encodebytes = encodestring
10-
114
expanduser: Any
12-
13-
if sys.version_info >= (3, 0):
14-
StandardError = Exception
15-
else:
16-
from __builtin__ import StandardError as StandardError
17-
5+
StandardError = Exception
186
long_type: Any
197
unquote_str: Any
208
parse_qs_safe: Any

stubs/boto/boto/utils.pyi

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import datetime
2+
import io
23
import logging.handlers
34
import subprocess
4-
import sys
55
import time
66
from collections.abc import Callable, Iterable, Mapping, Sequence
77
from contextlib import AbstractContextManager
8+
from email.message import Message
9+
from hashlib import _Hash
810
from typing import IO, Any, TypeVar
911
from typing_extensions import TypeAlias
1012

@@ -13,30 +15,6 @@ import boto.connection
1315
_KT = TypeVar("_KT")
1416
_VT = TypeVar("_VT")
1517

16-
if sys.version_info >= (3,):
17-
# TODO move _StringIO definition into boto.compat once stubs exist and rename to StringIO
18-
import io
19-
20-
_StringIO: TypeAlias = io.StringIO
21-
22-
from hashlib import _Hash
23-
24-
_HashType: TypeAlias = _Hash
25-
26-
from email.message import Message as _Message
27-
else:
28-
# TODO move _StringIO definition into boto.compat once stubs exist and rename to StringIO
29-
import StringIO
30-
31-
_StringIO: TypeAlias = StringIO.StringIO[Any]
32-
33-
from hashlib import _hash
34-
35-
_HashType: TypeAlias = _hash
36-
37-
# TODO use email.message.Message once stubs exist
38-
_Message: TypeAlias = Any
39-
4018
_Provider: TypeAlias = Any # TODO replace this with boto.provider.Provider once stubs exist
4119
_LockType: TypeAlias = Any # TODO replace this with _thread.LockType once stubs exist
4220

@@ -83,7 +61,7 @@ def fetch_file(
8361
class ShellCommand:
8462
exit_code: int
8563
command: subprocess._CMD
86-
log_fp: _StringIO
64+
log_fp: io.StringIO
8765
wait: bool
8866
fail_fast: bool
8967
def __init__(
@@ -121,9 +99,9 @@ class LRUCache(dict[_KT, _VT]):
12199
_str: TypeAlias = str
122100

123101
class Password:
124-
hashfunc: Callable[[bytes], _HashType]
102+
hashfunc: Callable[[bytes], _Hash]
125103
str: _str | None
126-
def __init__(self, str: _str | None = ..., hashfunc: Callable[[bytes], _HashType] | None = ...) -> None: ...
104+
def __init__(self, str: _str | None = ..., hashfunc: Callable[[bytes], _Hash] | None = ...) -> None: ...
127105
def set(self, value: bytes | _str) -> None: ...
128106
def __eq__(self, other: _str | bytes | None) -> bool: ... # type: ignore[override]
129107
def __len__(self) -> int: ...
@@ -133,7 +111,7 @@ def notify(
133111
body: str | None = ...,
134112
html_body: Sequence[str] | str | None = ...,
135113
to_string: str | None = ...,
136-
attachments: Iterable[_Message] | None = ...,
114+
attachments: Iterable[Message] | None = ...,
137115
append_instance_id: bool = ...,
138116
) -> None: ...
139117
def get_utf8_value(value: str) -> bytes: ...

stubs/decorator/decorator.pyi

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import sys
21
from builtins import dict as _dict # alias to avoid conflicts with attribute name
32
from collections.abc import Callable, Iterator
4-
from typing import Any, NamedTuple, Pattern, TypeVar
3+
from contextlib import _GeneratorContextManager
4+
from inspect import getfullargspec as getfullargspec, iscoroutinefunction as iscoroutinefunction
5+
from typing import Any, Pattern, TypeVar
56
from typing_extensions import ParamSpec
67

78
_C = TypeVar("_C", bound=Callable[..., Any])
@@ -11,25 +12,6 @@ _P = ParamSpec("_P")
1112

1213
def get_init(cls: type) -> None: ...
1314

14-
if sys.version_info >= (3,):
15-
from inspect import getfullargspec as getfullargspec, iscoroutinefunction as iscoroutinefunction
16-
else:
17-
class FullArgSpec(NamedTuple):
18-
args: list[str]
19-
varargs: str | None
20-
varkw: str | None
21-
defaults: tuple[Any, ...]
22-
kwonlyargs: list[str]
23-
kwonlydefaults: dict[str, Any]
24-
annotations: dict[str, Any]
25-
def iscoroutinefunction(f: Callable[..., Any]) -> bool: ...
26-
def getfullargspec(func: Any) -> FullArgSpec: ...
27-
28-
if sys.version_info >= (3, 2):
29-
from contextlib import _GeneratorContextManager
30-
else:
31-
from contextlib import GeneratorContextManager as _GeneratorContextManager
32-
3315
DEF: Pattern[str]
3416

3517
class FunctionMaker:

stubs/entrypoints/entrypoints.pyi

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
import sys
22
from _typeshed import Self
33
from collections.abc import Iterator, Sequence
4+
from configparser import ConfigParser
45
from typing import Any
56

6-
if sys.version_info >= (3, 0):
7-
from configparser import ConfigParser
8-
else:
9-
from ConfigParser import ConfigParser
10-
117
if sys.version_info >= (3, 8):
128
from re import Pattern
139
else:

stubs/humanfriendly/humanfriendly/compat.pyi

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
1-
import sys
1+
from html.parser import HTMLParser as HTMLParser
2+
from io import StringIO as StringIO
23

3-
if sys.version_info >= (3, 0):
4-
unicode = str
5-
unichr = chr
6-
basestring = str
7-
interactive_prompt = input
8-
from html.parser import HTMLParser as HTMLParser
9-
from io import StringIO as StringIO
10-
else:
11-
unicode = unicode
12-
unichr = unichr
13-
basestring = basestring
14-
interactive_prompt = raw_input # noqa: F821 # exists as a builtin in Python 2, but not in Python 3
15-
from StringIO import StringIO as StringIO
16-
17-
from HTMLParser import HTMLParser as HTMLParser
4+
unicode = str
5+
unichr = chr
6+
basestring = str
7+
interactive_prompt = input
188

199
def coerce_string(value): ...
2010
def is_string(value): ...

stubs/mypy-extensions/mypy_extensions.pyi

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import abc
2-
import sys
32
from _typeshed import Self
43
from typing import Any, Callable, Generic, ItemsView, KeysView, Mapping, TypeVar, ValuesView
54

@@ -15,16 +14,9 @@ class _TypedDict(Mapping[str, object], metaclass=abc.ABCMeta):
1514
# Mypy plugin hook for 'pop' expects that 'default' has a type variable type.
1615
def pop(self, k: NoReturn, default: _T = ...) -> object: ... # type: ignore
1716
def update(self: Self, __m: Self) -> None: ...
18-
if sys.version_info >= (3, 0):
19-
def items(self) -> ItemsView[str, object]: ...
20-
def keys(self) -> KeysView[str]: ...
21-
def values(self) -> ValuesView[object]: ...
22-
else:
23-
def has_key(self, k: str) -> bool: ...
24-
def viewitems(self) -> ItemsView[str, object]: ...
25-
def viewkeys(self) -> KeysView[str]: ...
26-
def viewvalues(self) -> ValuesView[object]: ...
27-
17+
def items(self) -> ItemsView[str, object]: ...
18+
def keys(self) -> KeysView[str]: ...
19+
def values(self) -> ValuesView[object]: ...
2820
def __delitem__(self, k: NoReturn) -> None: ...
2921

3022
def TypedDict(typename: str, fields: dict[str, type[Any]], total: bool = ...) -> type[dict[str, Any]]: ...

stubs/paramiko/paramiko/common.pyi

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import sys
21
from typing import Protocol
32
from typing_extensions import TypeAlias
43

@@ -100,12 +99,8 @@ max_byte: bytes
10099
cr_byte: bytes
101100
linefeed_byte: bytes
102101
crlf: bytes
103-
if sys.version_info >= (3, 0):
104-
cr_byte_value: int
105-
linefeed_byte_value: int
106-
else:
107-
cr_byte_value: bytes
108-
linefeed_byte_value: bytes
102+
cr_byte_value: int
103+
linefeed_byte_value: int
109104

110105
class _SupportsAsBytes(Protocol):
111106
def asbytes(self) -> bytes: ...

stubs/paramiko/paramiko/kex_curve25519.pyi

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
import sys
21
from _typeshed import ReadableBuffer as ReadableBuffer
32
from collections.abc import Callable
3+
from hashlib import _Hash
44

55
from cryptography.hazmat.primitives.asymmetric.x25519 import X25519PrivateKey
66
from paramiko.message import Message
77
from paramiko.transport import Transport
88

9-
if sys.version_info >= (3, 0):
10-
from hashlib import _Hash
11-
else:
12-
from hashlib import _hash as _Hash
13-
149
c_MSG_KEXECDH_INIT: bytes
1510
c_MSG_KEXECDH_REPLY: bytes
1611

stubs/paramiko/paramiko/kex_ecdh_nist.pyi

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
import sys
21
from _typeshed import ReadableBuffer
32
from collections.abc import Callable
3+
from hashlib import _Hash
44

55
from cryptography.hazmat.primitives.asymmetric.ec import EllipticCurve, EllipticCurvePrivateKey, EllipticCurvePublicKey
66
from paramiko.message import Message
77
from paramiko.transport import Transport
88

9-
if sys.version_info >= (3, 0):
10-
from hashlib import _Hash
11-
else:
12-
from hashlib import _hash as _Hash
13-
149
c_MSG_KEXECDH_INIT: bytes
1510
c_MSG_KEXECDH_REPLY: bytes
1611

stubs/paramiko/paramiko/kex_gex.pyi

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
import sys
21
from _typeshed import ReadableBuffer
32
from collections.abc import Callable
3+
from hashlib import _Hash
44

55
from paramiko.message import Message
66
from paramiko.transport import Transport
77

8-
if sys.version_info >= (3, 0):
9-
from hashlib import _Hash
10-
else:
11-
from hashlib import _hash as _Hash
12-
138
c_MSG_KEXDH_GEX_REQUEST_OLD: bytes
149
c_MSG_KEXDH_GEX_GROUP: bytes
1510
c_MSG_KEXDH_GEX_INIT: bytes

stubs/paramiko/paramiko/kex_group1.pyi

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
import sys
21
from _typeshed import ReadableBuffer
32
from collections.abc import Callable
3+
from hashlib import _Hash
44

55
from paramiko.message import Message
66
from paramiko.transport import Transport
77

8-
if sys.version_info >= (3, 0):
9-
from hashlib import _Hash
10-
else:
11-
from hashlib import _hash as _Hash
12-
138
c_MSG_KEXDH_INIT: bytes
149
c_MSG_KEXDH_REPLY: bytes
1510
b7fffffffffffffff: bytes

stubs/paramiko/paramiko/kex_group14.pyi

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
import sys
21
from _typeshed import ReadableBuffer
32
from collections.abc import Callable
3+
from hashlib import _Hash
44

55
from paramiko.kex_group1 import KexGroup1 as KexGroup1
66

7-
if sys.version_info >= (3, 0):
8-
from hashlib import _Hash
9-
else:
10-
from hashlib import _hash as _Hash
11-
127
class KexGroup14(KexGroup1):
138
P: int
149
G: int

stubs/paramiko/paramiko/kex_group16.pyi

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
import sys
21
from _typeshed import ReadableBuffer
32
from collections.abc import Callable
3+
from hashlib import _Hash
44

55
from paramiko.kex_group1 import KexGroup1 as KexGroup1
66

7-
if sys.version_info >= (3, 0):
8-
from hashlib import _Hash
9-
else:
10-
from hashlib import _hash as _Hash
11-
127
class KexGroup16SHA512(KexGroup1):
138
name: str
149
P: int

stubs/paramiko/paramiko/message.pyi

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
1-
import sys
21
from collections.abc import Iterable
2+
from io import BytesIO
33
from typing import Any
4-
from typing_extensions import TypeAlias
54

65
from .common import _LikeBytes
76

8-
if sys.version_info >= (3, 0):
9-
from io import BytesIO
10-
else:
11-
from StringIO import StringIO
12-
13-
BytesIO: TypeAlias = StringIO[bytes]
14-
157
class Message:
168
big_int: int
179
packet: BytesIO

stubs/paramiko/paramiko/packet.pyi

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import sys
21
from collections.abc import Callable
2+
from hashlib import _Hash
33
from logging import Logger
44
from socket import socket
55
from typing import Any
@@ -8,11 +8,6 @@ from cryptography.hazmat.primitives.ciphers import Cipher
88
from paramiko.compress import ZlibCompressor, ZlibDecompressor
99
from paramiko.message import Message
1010

11-
if sys.version_info >= (3, 0):
12-
from hashlib import _Hash
13-
else:
14-
from hashlib import _hash as _Hash
15-
1611
def compute_hmac(key: bytes, message: bytes, digest_class: _Hash) -> bytes: ...
1712

1813
class NeedRekeyException(Exception): ...

0 commit comments

Comments
 (0)