From fa9d5a5e9f1cd03aded2ba62934b7a028d3f4e6e Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Sun, 11 Apr 2021 06:44:18 -0700 Subject: [PATCH] future first: switch the order of some if statements (#5206) Since we're adding this to our contribution guidelines in https://github.com/python/typeshed/pull/5205 --- stdlib/_codecs.pyi | 8 +++---- stdlib/base64.pyi | 8 +++---- stdlib/binascii.pyi | 10 ++++---- stdlib/calendar.pyi | 6 ++--- stdlib/collections/__init__.pyi | 6 ++--- stdlib/locale.pyi | 6 ++--- stdlib/ssl.pyi | 12 +++++----- stdlib/subprocess.pyi | 6 ++--- stdlib/sunau.pyi | 7 +++--- stdlib/wave.pyi | 7 +++--- stdlib/weakref.pyi | 24 +++++++++---------- stdlib/wsgiref/simple_server.pyi | 6 ++--- stdlib/wsgiref/util.pyi | 6 ++--- stdlib/wsgiref/validate.pyi | 14 +++++------ stubs/PyYAML/yaml/__init__.pyi | 6 ++--- stubs/Werkzeug/werkzeug/http.pyi | 10 ++++---- stubs/Werkzeug/werkzeug/middleware/lint.pyi | 6 ++--- stubs/Werkzeug/werkzeug/serving.pyi | 14 +++++------ stubs/Werkzeug/werkzeug/test.pyi | 8 +++---- stubs/mypy-extensions/mypy_extensions.pyi | 10 ++++---- stubs/paramiko/paramiko/common.pyi | 8 +++---- stubs/paramiko/paramiko/kex_curve25519.pyi | 6 ++--- stubs/paramiko/paramiko/kex_ecdh_nist.pyi | 6 ++--- stubs/paramiko/paramiko/kex_gex.pyi | 6 ++--- stubs/paramiko/paramiko/kex_group1.pyi | 6 ++--- stubs/paramiko/paramiko/kex_group14.pyi | 6 ++--- stubs/paramiko/paramiko/kex_group16.pyi | 6 ++--- stubs/paramiko/paramiko/message.pyi | 6 ++--- stubs/paramiko/paramiko/packet.pyi | 6 ++--- stubs/paramiko/paramiko/py3compat.pyi | 14 +++++------ stubs/paramiko/paramiko/util.pyi | 6 ++--- stubs/protobuf/google/protobuf/message.pyi | 6 ++--- stubs/requests/requests/cookies.pyi | 6 ++--- .../requests/packages/urllib3/connection.pyi | 9 ++++--- stubs/typing-extensions/typing_extensions.pyi | 10 ++++---- stubs/xxhash/xxhash.pyi | 6 ++--- 36 files changed, 147 insertions(+), 146 deletions(-) diff --git a/stdlib/_codecs.pyi b/stdlib/_codecs.pyi index 2316cdbbc..fbb014aad 100644 --- a/stdlib/_codecs.pyi +++ b/stdlib/_codecs.pyi @@ -6,12 +6,12 @@ from typing import Any, Callable, Dict, Optional, Text, Tuple, Union _Handler = Callable[[Exception], Tuple[Text, int]] _String = Union[bytes, str] _Errors = Union[str, Text, None] -if sys.version_info < (3, 0): - _Decodable = Union[bytes, Text] - _Encodable = Union[bytes, Text] -else: +if sys.version_info >= (3, 0): _Decodable = bytes _Encodable = str +else: + _Decodable = Union[bytes, Text] + _Encodable = Union[bytes, Text] # This type is not exposed; it is defined in unicodeobject.c class _EncodingMap(object): diff --git a/stdlib/base64.pyi b/stdlib/base64.pyi index 01be704aa..01d304dc7 100644 --- a/stdlib/base64.pyi +++ b/stdlib/base64.pyi @@ -1,12 +1,12 @@ import sys from typing import IO, Optional, Union -if sys.version_info < (3,): - _encodable = Union[bytes, unicode] - _decodable = Union[bytes, unicode] -else: +if sys.version_info >= (3, 0): _encodable = bytes _decodable = Union[bytes, str] +else: + _encodable = Union[bytes, unicode] + _decodable = Union[bytes, unicode] def b64encode(s: _encodable, altchars: Optional[bytes] = ...) -> bytes: ... def b64decode(s: _decodable, altchars: Optional[bytes] = ..., validate: bool = ...) -> bytes: ... diff --git a/stdlib/binascii.pyi b/stdlib/binascii.pyi index d4141b9c4..db843ad6c 100644 --- a/stdlib/binascii.pyi +++ b/stdlib/binascii.pyi @@ -1,15 +1,15 @@ import sys from typing import Text, Union -if sys.version_info < (3,): - # Python 2 accepts unicode ascii pretty much everywhere. - _Bytes = Text - _Ascii = Text -else: +if sys.version_info >= (3, 0): # But since Python 3.3 ASCII-only unicode strings are accepted by the # a2b_* functions. _Bytes = bytes _Ascii = Union[bytes, str] +else: + # Python 2 accepts unicode ascii pretty much everywhere. + _Bytes = Text + _Ascii = Text def a2b_uu(__data: _Ascii) -> bytes: ... diff --git a/stdlib/calendar.pyi b/stdlib/calendar.pyi index af2aa83ed..0737062de 100644 --- a/stdlib/calendar.pyi +++ b/stdlib/calendar.pyi @@ -76,14 +76,14 @@ class HTMLCalendar(Calendar): cssclass_year: str cssclass_year_head: str -if sys.version_info < (3, 0): - class TimeEncoding: +if sys.version_info >= (3, 0): + class different_locale: def __init__(self, locale: _LocaleType) -> None: ... def __enter__(self) -> _LocaleType: ... def __exit__(self, *args: Any) -> None: ... else: - class different_locale: + class TimeEncoding: def __init__(self, locale: _LocaleType) -> None: ... def __enter__(self) -> _LocaleType: ... def __exit__(self, *args: Any) -> None: ... diff --git a/stdlib/collections/__init__.pyi b/stdlib/collections/__init__.pyi index c7633fcdd..76ec87661 100644 --- a/stdlib/collections/__init__.pyi +++ b/stdlib/collections/__init__.pyi @@ -1,9 +1,7 @@ import sys from typing import Any, Dict, Generic, List, Optional, Tuple, Type, TypeVar, Union, overload -if sys.version_info < (3, 10): - from _collections_abc import * -else: +if sys.version_info >= (3, 10): from typing import ( Callable, ItemsView, @@ -17,6 +15,8 @@ else: Sequence, ValuesView, ) +else: + from _collections_abc import * _S = TypeVar("_S") _T = TypeVar("_T") diff --git a/stdlib/locale.pyi b/stdlib/locale.pyi index c5e25c95a..920c006cd 100644 --- a/stdlib/locale.pyi +++ b/stdlib/locale.pyi @@ -3,10 +3,10 @@ from decimal import Decimal from typing import Any, Callable, Dict, Iterable, List, Mapping, Optional, Sequence, Tuple, Union # workaround for mypy#2010 -if sys.version_info < (3,): - from __builtin__ import str as _str -else: +if sys.version_info >= (3, 0): from builtins import str as _str +else: + from __builtin__ import str as _str CODESET: int D_T_FMT: int diff --git a/stdlib/ssl.pyi b/stdlib/ssl.pyi index c59df13e7..160501d1e 100644 --- a/stdlib/ssl.pyi +++ b/stdlib/ssl.pyi @@ -228,16 +228,16 @@ class _ASN1Object(NamedTuple): longname: str oid: str -if sys.version_info < (3,): - class Purpose(_ASN1Object): - SERVER_AUTH: ClassVar[Purpose] - CLIENT_AUTH: ClassVar[Purpose] - -else: +if sys.version_info >= (3, 0): class Purpose(_ASN1Object, enum.Enum): SERVER_AUTH: _ASN1Object CLIENT_AUTH: _ASN1Object +else: + class Purpose(_ASN1Object): + SERVER_AUTH: ClassVar[Purpose] + CLIENT_AUTH: ClassVar[Purpose] + class SSLSocket(socket.socket): context: SSLContext server_side: bool diff --git a/stdlib/subprocess.pyi b/stdlib/subprocess.pyi index df6eeb2ae..817baebc7 100644 --- a/stdlib/subprocess.pyi +++ b/stdlib/subprocess.pyi @@ -23,12 +23,12 @@ if sys.version_info >= (3, 9): # reveal_type(e.cmd) # Any, but morally is _CMD _FILE = Union[None, int, IO[Any]] _TXT = Union[bytes, str] -if sys.version_info < (3, 8): +if sys.version_info >= (3, 8): + _CMD = Union[AnyPath, Sequence[AnyPath]] +else: # Python 3.6 doesn't support _CMD being a single PathLike. # See: https://bugs.python.org/issue31961 _CMD = Union[_TXT, Sequence[AnyPath]] -else: - _CMD = Union[AnyPath, Sequence[AnyPath]] if sys.platform == "win32": _ENV = Mapping[str, str] else: diff --git a/stdlib/sunau.pyi b/stdlib/sunau.pyi index b9475937c..9d2f6ec17 100644 --- a/stdlib/sunau.pyi +++ b/stdlib/sunau.pyi @@ -20,9 +20,7 @@ AUDIO_FILE_ENCODING_ADPCM_G723_5: int AUDIO_FILE_ENCODING_ALAW_8: int AUDIO_UNKNOWN_SIZE: int -if sys.version_info < (3, 0): - _sunau_params = Tuple[int, int, int, int, str, str] -else: +if sys.version_info >= (3, 0): class _sunau_params(NamedTuple): nchannels: int sampwidth: int @@ -31,6 +29,9 @@ else: comptype: str compname: str +else: + _sunau_params = Tuple[int, int, int, int, str, str] + class Au_read: def __init__(self, f: _File) -> None: ... if sys.version_info >= (3, 3): diff --git a/stdlib/wave.pyi b/stdlib/wave.pyi index c89ba628e..d41563042 100644 --- a/stdlib/wave.pyi +++ b/stdlib/wave.pyi @@ -7,9 +7,7 @@ class Error(Exception): ... WAVE_FORMAT_PCM: int -if sys.version_info < (3, 0): - _wave_params = Tuple[int, int, int, int, str, str] -else: +if sys.version_info >= (3, 0): class _wave_params(NamedTuple): nchannels: int sampwidth: int @@ -18,6 +16,9 @@ else: comptype: str compname: str +else: + _wave_params = Tuple[int, int, int, int, str, str] + class Wave_read: def __init__(self, f: _File) -> None: ... if sys.version_info >= (3, 0): diff --git a/stdlib/weakref.pyi b/stdlib/weakref.pyi index 98f57ea60..b43b634d6 100644 --- a/stdlib/weakref.pyi +++ b/stdlib/weakref.pyi @@ -59,18 +59,18 @@ class WeakValueDictionary(MutableMapping[_KT, _VT]): def __iter__(self) -> Iterator[_KT]: ... def __str__(self) -> str: ... def copy(self) -> WeakValueDictionary[_KT, _VT]: ... - if sys.version_info < (3, 0): + if sys.version_info >= (3, 0): + # These are incompatible with Mapping + def keys(self) -> Iterator[_KT]: ... # type: ignore + def values(self) -> Iterator[_VT]: ... # type: ignore + def items(self) -> Iterator[Tuple[_KT, _VT]]: ... # type: ignore + else: def keys(self) -> List[_KT]: ... def values(self) -> List[_VT]: ... def items(self) -> List[Tuple[_KT, _VT]]: ... def iterkeys(self) -> Iterator[_KT]: ... def itervalues(self) -> Iterator[_VT]: ... def iteritems(self) -> Iterator[Tuple[_KT, _VT]]: ... - else: - # These are incompatible with Mapping - def keys(self) -> Iterator[_KT]: ... # type: ignore - def values(self) -> Iterator[_VT]: ... # type: ignore - def items(self) -> Iterator[Tuple[_KT, _VT]]: ... # type: ignore def itervaluerefs(self) -> Iterator[KeyedRef[_KT, _VT]]: ... def valuerefs(self) -> List[KeyedRef[_KT, _VT]]: ... @@ -95,7 +95,12 @@ class WeakKeyDictionary(MutableMapping[_KT, _VT]): def __iter__(self) -> Iterator[_KT]: ... def __str__(self) -> str: ... def copy(self) -> WeakKeyDictionary[_KT, _VT]: ... - if sys.version_info < (3, 0): + if sys.version_info >= (3, 0): + # These are incompatible with Mapping + def keys(self) -> Iterator[_KT]: ... # type: ignore + def values(self) -> Iterator[_VT]: ... # type: ignore + def items(self) -> Iterator[Tuple[_KT, _VT]]: ... # type: ignore + else: def keys(self) -> List[_KT]: ... def values(self) -> List[_VT]: ... def items(self) -> List[Tuple[_KT, _VT]]: ... @@ -103,11 +108,6 @@ class WeakKeyDictionary(MutableMapping[_KT, _VT]): def itervalues(self) -> Iterator[_VT]: ... def iteritems(self) -> Iterator[Tuple[_KT, _VT]]: ... def iterkeyrefs(self) -> Iterator[ref[_KT]]: ... - else: - # These are incompatible with Mapping - def keys(self) -> Iterator[_KT]: ... # type: ignore - def values(self) -> Iterator[_VT]: ... # type: ignore - def items(self) -> Iterator[Tuple[_KT, _VT]]: ... # type: ignore def keyrefs(self) -> List[ref[_KT]]: ... if sys.version_info >= (3, 4): diff --git a/stdlib/wsgiref/simple_server.pyi b/stdlib/wsgiref/simple_server.pyi index 66cd94fa7..74511ece2 100644 --- a/stdlib/wsgiref/simple_server.pyi +++ b/stdlib/wsgiref/simple_server.pyi @@ -4,10 +4,10 @@ from typing import List, Optional, Type, TypeVar, overload from .handlers import SimpleHandler from .types import ErrorStream, StartResponse, WSGIApplication, WSGIEnvironment -if sys.version_info < (3,): - from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer -else: +if sys.version_info >= (3, 0): from http.server import BaseHTTPRequestHandler, HTTPServer +else: + from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer server_version: str # undocumented sys_version: str # undocumented diff --git a/stdlib/wsgiref/util.pyi b/stdlib/wsgiref/util.pyi index 0382fc285..1c66bc1fa 100644 --- a/stdlib/wsgiref/util.pyi +++ b/stdlib/wsgiref/util.pyi @@ -10,10 +10,10 @@ class FileWrapper: def __init__(self, filelike: IO[bytes], blksize: int = ...) -> None: ... def __getitem__(self, key: Any) -> bytes: ... def __iter__(self) -> FileWrapper: ... - if sys.version_info < (3,): - def next(self) -> bytes: ... - else: + if sys.version_info >= (3, 0): def __next__(self) -> bytes: ... + else: + def next(self) -> bytes: ... def guess_scheme(environ: WSGIEnvironment) -> str: ... def application_uri(environ: WSGIEnvironment) -> str: ... diff --git a/stdlib/wsgiref/validate.pyi b/stdlib/wsgiref/validate.pyi index 570546e65..bc9f0b8c6 100644 --- a/stdlib/wsgiref/validate.pyi +++ b/stdlib/wsgiref/validate.pyi @@ -9,12 +9,12 @@ def validator(application: WSGIApplication) -> WSGIApplication: ... class InputWrapper: input: InputStream def __init__(self, wsgi_input: InputStream) -> None: ... - if sys.version_info < (3,): - def read(self, size: int = ...) -> bytes: ... - def readline(self) -> bytes: ... - else: + if sys.version_info >= (3, 0): def read(self, size: int) -> bytes: ... def readline(self, size: int = ...) -> bytes: ... + else: + def read(self, size: int = ...) -> bytes: ... + def readline(self) -> bytes: ... def readlines(self, hint: int = ...) -> bytes: ... def __iter__(self) -> Iterable[bytes]: ... def close(self) -> NoReturn: ... @@ -44,9 +44,9 @@ class IteratorWrapper: check_start_response: Optional[bool] def __init__(self, wsgi_iterator: Iterator[bytes], check_start_response: Optional[bool]) -> None: ... def __iter__(self) -> IteratorWrapper: ... - if sys.version_info < (3,): - def next(self) -> bytes: ... - else: + if sys.version_info >= (3, 0): def __next__(self) -> bytes: ... + else: + def next(self) -> bytes: ... def close(self) -> None: ... def __del__(self) -> None: ... diff --git a/stubs/PyYAML/yaml/__init__.pyi b/stubs/PyYAML/yaml/__init__.pyi index 50802e428..09e06f65c 100644 --- a/stubs/PyYAML/yaml/__init__.pyi +++ b/stubs/PyYAML/yaml/__init__.pyi @@ -11,10 +11,10 @@ from yaml.tokens import * # noqa: F403 from . import resolver as resolver # Help mypy a bit; this is implied by loader and dumper from .cyaml import * -if sys.version_info < (3,): - _Str = Union[Text, str] -else: +if sys.version_info >= (3, 0): _Str = str +else: + _Str = Union[Text, str] # FIXME: the functions really return py2:unicode/py3:str if encoding is None, otherwise py2:str/py3:bytes. Waiting for python/mypy#5621 _Yaml = Any diff --git a/stubs/Werkzeug/werkzeug/http.pyi b/stubs/Werkzeug/werkzeug/http.pyi index e124c3bfc..55a1dbd43 100644 --- a/stubs/Werkzeug/werkzeug/http.pyi +++ b/stubs/Werkzeug/werkzeug/http.pyi @@ -32,14 +32,14 @@ from .datastructures import ( WWWAuthenticate, ) -if sys.version_info < (3,): - _Str = TypeVar("_Str", str, unicode) - _ToBytes = Union[bytes, bytearray, buffer, unicode] - _ETagData = Union[str, unicode, bytearray, buffer, memoryview] -else: +if sys.version_info >= (3, 0): _Str = str _ToBytes = Union[bytes, bytearray, memoryview, str] _ETagData = Union[bytes, bytearray, memoryview] +else: + _Str = TypeVar("_Str", str, unicode) + _ToBytes = Union[bytes, bytearray, buffer, unicode] + _ETagData = Union[str, unicode, bytearray, buffer, memoryview] _T = TypeVar("_T") _U = TypeVar("_U") diff --git a/stubs/Werkzeug/werkzeug/middleware/lint.pyi b/stubs/Werkzeug/werkzeug/middleware/lint.pyi index 82ab8699e..532484f67 100644 --- a/stubs/Werkzeug/werkzeug/middleware/lint.pyi +++ b/stubs/Werkzeug/werkzeug/middleware/lint.pyi @@ -45,10 +45,10 @@ class GuardedIterator(object): chunks: List[int] def __init__(self, iterator: Iterable[str], headers_set: bool, chunks: List[int]) -> None: ... def __iter__(self) -> GuardedIterator: ... - if sys.version_info < (3,): - def next(self) -> str: ... - else: + if sys.version_info >= (3, 0): def __next__(self) -> str: ... + else: + def next(self) -> str: ... def close(self) -> None: ... class LintMiddleware(object): diff --git a/stubs/Werkzeug/werkzeug/serving.pyi b/stubs/Werkzeug/werkzeug/serving.pyi index d75a39567..1df2b29e0 100644 --- a/stubs/Werkzeug/werkzeug/serving.pyi +++ b/stubs/Werkzeug/werkzeug/serving.pyi @@ -1,21 +1,21 @@ import sys from typing import Any, Optional -if sys.version_info < (3,): - from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer - from SocketServer import ThreadingMixIn -else: +if sys.version_info >= (3, 0): from http.server import BaseHTTPRequestHandler, HTTPServer from socketserver import ThreadingMixIn +else: + from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer + from SocketServer import ThreadingMixIn if sys.platform == "win32": class ForkingMixIn(object): ... else: - if sys.version_info < (3,): - from SocketServer import ForkingMixIn as ForkingMixIn - else: + if sys.version_info >= (3, 0): from socketserver import ForkingMixIn as ForkingMixIn + else: + from SocketServer import ForkingMixIn as ForkingMixIn class _SslDummy: def __getattr__(self, name): ... diff --git a/stubs/Werkzeug/werkzeug/test.pyi b/stubs/Werkzeug/werkzeug/test.pyi index 7624869f3..19bb5740d 100644 --- a/stubs/Werkzeug/werkzeug/test.pyi +++ b/stubs/Werkzeug/werkzeug/test.pyi @@ -3,12 +3,12 @@ from _typeshed.wsgi import WSGIEnvironment from typing import Any, Generic, Optional, Text, Tuple, Type, TypeVar, overload from typing_extensions import Literal -if sys.version_info < (3,): - from cookielib import CookieJar - from urllib2 import Request as U2Request -else: +if sys.version_info >= (3, 0): from http.cookiejar import CookieJar from urllib.request import Request as U2Request +else: + from cookielib import CookieJar + from urllib2 import Request as U2Request def stream_encode_multipart( values, use_tempfile: int = ..., threshold=..., boundary: Optional[Any] = ..., charset: Text = ... diff --git a/stubs/mypy-extensions/mypy_extensions.pyi b/stubs/mypy-extensions/mypy_extensions.pyi index 11a1fed9c..a7bd0711f 100644 --- a/stubs/mypy-extensions/mypy_extensions.pyi +++ b/stubs/mypy-extensions/mypy_extensions.pyi @@ -14,15 +14,15 @@ class _TypedDict(Mapping[str, object], metaclass=abc.ABCMeta): # Mypy plugin hook for 'pop' expects that 'default' has a type variable type. def pop(self, k: NoReturn, default: _T = ...) -> object: ... # type: ignore def update(self: _T, __m: _T) -> None: ... - if sys.version_info < (3, 0): + if sys.version_info >= (3, 0): + def items(self) -> ItemsView[str, object]: ... + def keys(self) -> KeysView[str]: ... + def values(self) -> ValuesView[object]: ... + else: def has_key(self, k: str) -> bool: ... def viewitems(self) -> ItemsView[str, object]: ... def viewkeys(self) -> KeysView[str]: ... def viewvalues(self) -> ValuesView[object]: ... - else: - def items(self) -> ItemsView[str, object]: ... - def keys(self) -> KeysView[str]: ... - def values(self) -> ValuesView[object]: ... def __delitem__(self, k: NoReturn) -> None: ... def TypedDict(typename: str, fields: Dict[str, Type[Any]], total: bool = ...) -> Type[Dict[str, Any]]: ... diff --git a/stubs/paramiko/paramiko/common.pyi b/stubs/paramiko/paramiko/common.pyi index 40855b4b7..cb72a12f7 100644 --- a/stubs/paramiko/paramiko/common.pyi +++ b/stubs/paramiko/paramiko/common.pyi @@ -99,12 +99,12 @@ max_byte: bytes cr_byte: bytes linefeed_byte: bytes crlf: bytes -if sys.version_info < (3, 0): - cr_byte_value: bytes - linefeed_byte_value: bytes -else: +if sys.version_info >= (3, 0): cr_byte_value: int linefeed_byte_value: int +else: + cr_byte_value: bytes + linefeed_byte_value: bytes class _SupportsAsBytes(Protocol): def asbytes(self) -> bytes: ... diff --git a/stubs/paramiko/paramiko/kex_curve25519.pyi b/stubs/paramiko/paramiko/kex_curve25519.pyi index b408c4182..aaf2de78c 100644 --- a/stubs/paramiko/paramiko/kex_curve25519.pyi +++ b/stubs/paramiko/paramiko/kex_curve25519.pyi @@ -6,10 +6,10 @@ from cryptography.hazmat.primitives.asymmetric.x25519 import X25519PrivateKey from paramiko.message import Message from paramiko.transport import Transport -if sys.version_info < (3, 0): - from hashlib import _hash as _Hash -else: +if sys.version_info >= (3, 0): from hashlib import _Hash +else: + from hashlib import _hash as _Hash c_MSG_KEXECDH_INIT: bytes c_MSG_KEXECDH_REPLY: bytes diff --git a/stubs/paramiko/paramiko/kex_ecdh_nist.pyi b/stubs/paramiko/paramiko/kex_ecdh_nist.pyi index 223d7d4ab..b1b78a075 100644 --- a/stubs/paramiko/paramiko/kex_ecdh_nist.pyi +++ b/stubs/paramiko/paramiko/kex_ecdh_nist.pyi @@ -6,10 +6,10 @@ from cryptography.hazmat.primitives.asymmetric.ec2 import EllipticCurve, Ellipti from paramiko.message import Message from paramiko.transport import Transport -if sys.version_info < (3, 0): - from hashlib import _hash as _Hash -else: +if sys.version_info >= (3, 0): from hashlib import _Hash +else: + from hashlib import _hash as _Hash c_MSG_KEXECDH_INIT: bytes c_MSG_KEXECDH_REPLY: bytes diff --git a/stubs/paramiko/paramiko/kex_gex.pyi b/stubs/paramiko/paramiko/kex_gex.pyi index 50bb4e4a3..32e4a401d 100644 --- a/stubs/paramiko/paramiko/kex_gex.pyi +++ b/stubs/paramiko/paramiko/kex_gex.pyi @@ -5,10 +5,10 @@ from typing import Callable, Optional from paramiko.message import Message from paramiko.transport import Transport -if sys.version_info < (3, 0): - from hashlib import _hash as _Hash -else: +if sys.version_info >= (3, 0): from hashlib import _Hash +else: + from hashlib import _hash as _Hash c_MSG_KEXDH_GEX_REQUEST_OLD: bytes c_MSG_KEXDH_GEX_GROUP: bytes diff --git a/stubs/paramiko/paramiko/kex_group1.pyi b/stubs/paramiko/paramiko/kex_group1.pyi index 8bdbe1384..8b6ae8842 100644 --- a/stubs/paramiko/paramiko/kex_group1.pyi +++ b/stubs/paramiko/paramiko/kex_group1.pyi @@ -5,10 +5,10 @@ from typing import Callable from paramiko.message import Message from paramiko.transport import Transport -if sys.version_info < (3, 0): - from hashlib import _hash as _Hash -else: +if sys.version_info >= (3, 0): from hashlib import _Hash +else: + from hashlib import _hash as _Hash c_MSG_KEXDH_INIT: bytes c_MSG_KEXDH_REPLY: bytes diff --git a/stubs/paramiko/paramiko/kex_group14.pyi b/stubs/paramiko/paramiko/kex_group14.pyi index beaf4b4cc..276f9e5cd 100644 --- a/stubs/paramiko/paramiko/kex_group14.pyi +++ b/stubs/paramiko/paramiko/kex_group14.pyi @@ -4,10 +4,10 @@ from typing import Callable from paramiko.kex_group1 import KexGroup1 as KexGroup1 -if sys.version_info < (3, 0): - from hashlib import _hash as _Hash -else: +if sys.version_info >= (3, 0): from hashlib import _Hash +else: + from hashlib import _hash as _Hash class KexGroup14(KexGroup1): P: int diff --git a/stubs/paramiko/paramiko/kex_group16.pyi b/stubs/paramiko/paramiko/kex_group16.pyi index b495410c9..d85490cd4 100644 --- a/stubs/paramiko/paramiko/kex_group16.pyi +++ b/stubs/paramiko/paramiko/kex_group16.pyi @@ -4,10 +4,10 @@ from typing import Callable from paramiko.kex_group1 import KexGroup1 as KexGroup1 -if sys.version_info < (3, 0): - from hashlib import _hash as _Hash -else: +if sys.version_info >= (3, 0): from hashlib import _Hash +else: + from hashlib import _hash as _Hash class KexGroup16SHA512(KexGroup1): name: str diff --git a/stubs/paramiko/paramiko/message.pyi b/stubs/paramiko/paramiko/message.pyi index 49614a2b2..5f43304d4 100644 --- a/stubs/paramiko/paramiko/message.pyi +++ b/stubs/paramiko/paramiko/message.pyi @@ -3,12 +3,12 @@ from typing import Any, Iterable, List, Optional, Text from .common import _LikeBytes -if sys.version_info < (3, 0): +if sys.version_info >= (3, 0): + from io import BytesIO +else: from StringIO import StringIO BytesIO = StringIO[bytes] -else: - from io import BytesIO class Message: big_int: int diff --git a/stubs/paramiko/paramiko/packet.pyi b/stubs/paramiko/paramiko/packet.pyi index fdd1e801d..ffbf10ef7 100644 --- a/stubs/paramiko/paramiko/packet.pyi +++ b/stubs/paramiko/paramiko/packet.pyi @@ -7,10 +7,10 @@ from cryptography.hazmat.primitives.ciphers import Cipher from paramiko.compress import ZlibCompressor, ZlibDecompressor from paramiko.message import Message -if sys.version_info < (3, 0): - from hashlib import _hash as _Hash -else: +if sys.version_info >= (3, 0): from hashlib import _Hash +else: + from hashlib import _hash as _Hash def compute_hmac(key: bytes, message: bytes, digest_class: _Hash) -> bytes: ... diff --git a/stubs/paramiko/paramiko/py3compat.pyi b/stubs/paramiko/paramiko/py3compat.pyi index b9a7a9b9c..4b9e83d49 100644 --- a/stubs/paramiko/paramiko/py3compat.pyi +++ b/stubs/paramiko/paramiko/py3compat.pyi @@ -16,18 +16,18 @@ def input(prompt: Any) -> str: ... def decodebytes(s: bytes) -> bytes: ... def encodebytes(s: bytes) -> bytes: ... -if sys.version_info < (3, 0): - import __builtin__ as builtins - import cStringIO - - StringIO = cStringIO.StringIO - BytesIO = StringIO -else: +if sys.version_info >= (3, 0): import builtins as builtins import io StringIO = io.StringIO BytesIO = io.BytesIO +else: + import __builtin__ as builtins + import cStringIO + + StringIO = cStringIO.StringIO + BytesIO = StringIO def byte_ord(c: Union[int, str]) -> int: ... def byte_chr(c: int) -> bytes: ... diff --git a/stubs/paramiko/paramiko/util.pyi b/stubs/paramiko/paramiko/util.pyi index 404017e41..563360470 100644 --- a/stubs/paramiko/paramiko/util.pyi +++ b/stubs/paramiko/paramiko/util.pyi @@ -6,10 +6,10 @@ from typing import IO, AnyStr, Callable, Generic, List, Optional, Protocol, Text from paramiko.config import SSHConfig, SSHConfigDict from paramiko.hostkeys import HostKeys -if sys.version_info < (3, 0): - from hashlib import _hash as _Hash -else: +if sys.version_info >= (3, 0): from hashlib import _Hash +else: + from hashlib import _hash as _Hash class SupportsClose(Protocol): def close(self) -> None: ... diff --git a/stubs/protobuf/google/protobuf/message.pyi b/stubs/protobuf/google/protobuf/message.pyi index 177602be1..dd5541b15 100644 --- a/stubs/protobuf/google/protobuf/message.pyi +++ b/stubs/protobuf/google/protobuf/message.pyi @@ -10,10 +10,10 @@ class EncodeError(Error): ... _M = TypeVar("_M", bound=Message) # message type (of self) -if sys.version_info < (3,): - _Serialized = Union[bytes, buffer, unicode] -else: +if sys.version_info >= (3, 0): _Serialized = ByteString +else: + _Serialized = Union[bytes, buffer, unicode] class Message: DESCRIPTOR: Descriptor diff --git a/stubs/requests/requests/cookies.pyi b/stubs/requests/requests/cookies.pyi index c53d3f61f..673852193 100644 --- a/stubs/requests/requests/cookies.pyi +++ b/stubs/requests/requests/cookies.pyi @@ -1,10 +1,10 @@ import sys from typing import Any, MutableMapping -if sys.version_info < (3, 0): - from cookielib import CookieJar -else: +if sys.version_info >= (3, 0): from http.cookiejar import CookieJar +else: + from cookielib import CookieJar class MockRequest: type: Any diff --git a/stubs/requests/requests/packages/urllib3/connection.pyi b/stubs/requests/requests/packages/urllib3/connection.pyi index 4ba5ed586..39d0f6abb 100644 --- a/stubs/requests/requests/packages/urllib3/connection.pyi +++ b/stubs/requests/requests/packages/urllib3/connection.pyi @@ -6,13 +6,12 @@ from . import exceptions, util from .packages import ssl_match_hostname from .util import ssl_ -if sys.version_info < (3, 0): - from httplib import HTTPConnection as _HTTPConnection, HTTPException as HTTPException - class ConnectionError(Exception): ... - -else: +if sys.version_info >= (3, 0): from builtins import ConnectionError as ConnectionError from http.client import HTTPConnection as _HTTPConnection, HTTPException as HTTPException +else: + from httplib import HTTPConnection as _HTTPConnection, HTTPException as HTTPException + class ConnectionError(Exception): ... class DummyConnection: ... diff --git a/stubs/typing-extensions/typing_extensions.pyi b/stubs/typing-extensions/typing_extensions.pyi index 3ca636af8..8dd41b539 100644 --- a/stubs/typing-extensions/typing_extensions.pyi +++ b/stubs/typing-extensions/typing_extensions.pyi @@ -53,15 +53,15 @@ class _TypedDict(Mapping[str, object], metaclass=abc.ABCMeta): # Mypy plugin hook for 'pop' expects that 'default' has a type variable type. def pop(self, k: NoReturn, default: _T = ...) -> object: ... # type: ignore def update(self: _T, __m: _T) -> None: ... - if sys.version_info < (3, 0): + if sys.version_info >= (3, 0): + def items(self) -> ItemsView[str, object]: ... + def keys(self) -> KeysView[str]: ... + def values(self) -> ValuesView[object]: ... + else: def has_key(self, k: str) -> bool: ... def viewitems(self) -> ItemsView[str, object]: ... def viewkeys(self) -> KeysView[str]: ... def viewvalues(self) -> ValuesView[object]: ... - else: - def items(self) -> ItemsView[str, object]: ... - def keys(self) -> KeysView[str]: ... - def values(self) -> ValuesView[object]: ... def __delitem__(self, k: NoReturn) -> None: ... # TypedDict is a (non-subscriptable) special form. diff --git a/stubs/xxhash/xxhash.pyi b/stubs/xxhash/xxhash.pyi index 97b1a2d0e..d0f7a4932 100644 --- a/stubs/xxhash/xxhash.pyi +++ b/stubs/xxhash/xxhash.pyi @@ -1,10 +1,10 @@ import sys from _typeshed import ReadableBuffer -if sys.version_info < (3,): - from hashlib import _hash as _Hash -else: +if sys.version_info >= (3, 0): from hashlib import _Hash +else: + from hashlib import _hash as _Hash VERSION: str XXHASH_VERSION: str