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
This commit is contained in:
Shantanu
2021-04-11 06:44:18 -07:00
committed by GitHub
parent b308c1f964
commit fa9d5a5e9f
36 changed files with 147 additions and 146 deletions

View File

@@ -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

View File

@@ -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")

View File

@@ -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):

View File

@@ -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): ...

View File

@@ -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 = ...

View File

@@ -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]]: ...

View File

@@ -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: ...

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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: ...

View File

@@ -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: ...

View File

@@ -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: ...

View File

@@ -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

View File

@@ -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

View File

@@ -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: ...

View File

@@ -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.

View File

@@ -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