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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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