Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fa9d5a5

Browse files
authored
future first: switch the order of some if statements (#5206)
Since we're adding this to our contribution guidelines in #5205
1 parent b308c1f commit fa9d5a5

36 files changed

Lines changed: 147 additions & 146 deletions

stdlib/_codecs.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ from typing import Any, Callable, Dict, Optional, Text, Tuple, Union
66
_Handler = Callable[[Exception], Tuple[Text, int]]
77
_String = Union[bytes, str]
88
_Errors = Union[str, Text, None]
9-
if sys.version_info < (3, 0):
10-
_Decodable = Union[bytes, Text]
11-
_Encodable = Union[bytes, Text]
12-
else:
9+
if sys.version_info >= (3, 0):
1310
_Decodable = bytes
1411
_Encodable = str
12+
else:
13+
_Decodable = Union[bytes, Text]
14+
_Encodable = Union[bytes, Text]
1515

1616
# This type is not exposed; it is defined in unicodeobject.c
1717
class _EncodingMap(object):

stdlib/base64.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import sys
22
from typing import IO, Optional, Union
33

4-
if sys.version_info < (3,):
5-
_encodable = Union[bytes, unicode]
6-
_decodable = Union[bytes, unicode]
7-
else:
4+
if sys.version_info >= (3, 0):
85
_encodable = bytes
96
_decodable = Union[bytes, str]
7+
else:
8+
_encodable = Union[bytes, unicode]
9+
_decodable = Union[bytes, unicode]
1010

1111
def b64encode(s: _encodable, altchars: Optional[bytes] = ...) -> bytes: ...
1212
def b64decode(s: _decodable, altchars: Optional[bytes] = ..., validate: bool = ...) -> bytes: ...

stdlib/binascii.pyi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import sys
22
from typing import Text, Union
33

4-
if sys.version_info < (3,):
5-
# Python 2 accepts unicode ascii pretty much everywhere.
6-
_Bytes = Text
7-
_Ascii = Text
8-
else:
4+
if sys.version_info >= (3, 0):
95
# But since Python 3.3 ASCII-only unicode strings are accepted by the
106
# a2b_* functions.
117
_Bytes = bytes
128
_Ascii = Union[bytes, str]
9+
else:
10+
# Python 2 accepts unicode ascii pretty much everywhere.
11+
_Bytes = Text
12+
_Ascii = Text
1313

1414
def a2b_uu(__data: _Ascii) -> bytes: ...
1515

stdlib/calendar.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ class HTMLCalendar(Calendar):
7676
cssclass_year: str
7777
cssclass_year_head: str
7878

79-
if sys.version_info < (3, 0):
80-
class TimeEncoding:
79+
if sys.version_info >= (3, 0):
80+
class different_locale:
8181
def __init__(self, locale: _LocaleType) -> None: ...
8282
def __enter__(self) -> _LocaleType: ...
8383
def __exit__(self, *args: Any) -> None: ...
8484

8585
else:
86-
class different_locale:
86+
class TimeEncoding:
8787
def __init__(self, locale: _LocaleType) -> None: ...
8888
def __enter__(self) -> _LocaleType: ...
8989
def __exit__(self, *args: Any) -> None: ...

stdlib/collections/__init__.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import sys
22
from typing import Any, Dict, Generic, List, Optional, Tuple, Type, TypeVar, Union, overload
33

4-
if sys.version_info < (3, 10):
5-
from _collections_abc import *
6-
else:
4+
if sys.version_info >= (3, 10):
75
from typing import (
86
Callable,
97
ItemsView,
@@ -17,6 +15,8 @@ else:
1715
Sequence,
1816
ValuesView,
1917
)
18+
else:
19+
from _collections_abc import *
2020

2121
_S = TypeVar("_S")
2222
_T = TypeVar("_T")

stdlib/locale.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ from decimal import Decimal
33
from typing import Any, Callable, Dict, Iterable, List, Mapping, Optional, Sequence, Tuple, Union
44

55
# workaround for mypy#2010
6-
if sys.version_info < (3,):
7-
from __builtin__ import str as _str
8-
else:
6+
if sys.version_info >= (3, 0):
97
from builtins import str as _str
8+
else:
9+
from __builtin__ import str as _str
1010

1111
CODESET: int
1212
D_T_FMT: int

stdlib/ssl.pyi

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,16 +228,16 @@ class _ASN1Object(NamedTuple):
228228
longname: str
229229
oid: str
230230

231-
if sys.version_info < (3,):
232-
class Purpose(_ASN1Object):
233-
SERVER_AUTH: ClassVar[Purpose]
234-
CLIENT_AUTH: ClassVar[Purpose]
235-
236-
else:
231+
if sys.version_info >= (3, 0):
237232
class Purpose(_ASN1Object, enum.Enum):
238233
SERVER_AUTH: _ASN1Object
239234
CLIENT_AUTH: _ASN1Object
240235

236+
else:
237+
class Purpose(_ASN1Object):
238+
SERVER_AUTH: ClassVar[Purpose]
239+
CLIENT_AUTH: ClassVar[Purpose]
240+
241241
class SSLSocket(socket.socket):
242242
context: SSLContext
243243
server_side: bool

stdlib/subprocess.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ if sys.version_info >= (3, 9):
2323
# reveal_type(e.cmd) # Any, but morally is _CMD
2424
_FILE = Union[None, int, IO[Any]]
2525
_TXT = Union[bytes, str]
26-
if sys.version_info < (3, 8):
26+
if sys.version_info >= (3, 8):
27+
_CMD = Union[AnyPath, Sequence[AnyPath]]
28+
else:
2729
# Python 3.6 doesn't support _CMD being a single PathLike.
2830
# See: https://bugs.python.org/issue31961
2931
_CMD = Union[_TXT, Sequence[AnyPath]]
30-
else:
31-
_CMD = Union[AnyPath, Sequence[AnyPath]]
3232
if sys.platform == "win32":
3333
_ENV = Mapping[str, str]
3434
else:

stdlib/sunau.pyi

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ AUDIO_FILE_ENCODING_ADPCM_G723_5: int
2020
AUDIO_FILE_ENCODING_ALAW_8: int
2121
AUDIO_UNKNOWN_SIZE: int
2222

23-
if sys.version_info < (3, 0):
24-
_sunau_params = Tuple[int, int, int, int, str, str]
25-
else:
23+
if sys.version_info >= (3, 0):
2624
class _sunau_params(NamedTuple):
2725
nchannels: int
2826
sampwidth: int
@@ -31,6 +29,9 @@ else:
3129
comptype: str
3230
compname: str
3331

32+
else:
33+
_sunau_params = Tuple[int, int, int, int, str, str]
34+
3435
class Au_read:
3536
def __init__(self, f: _File) -> None: ...
3637
if sys.version_info >= (3, 3):

stdlib/wave.pyi

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ class Error(Exception): ...
77

88
WAVE_FORMAT_PCM: int
99

10-
if sys.version_info < (3, 0):
11-
_wave_params = Tuple[int, int, int, int, str, str]
12-
else:
10+
if sys.version_info >= (3, 0):
1311
class _wave_params(NamedTuple):
1412
nchannels: int
1513
sampwidth: int
@@ -18,6 +16,9 @@ else:
1816
comptype: str
1917
compname: str
2018

19+
else:
20+
_wave_params = Tuple[int, int, int, int, str, str]
21+
2122
class Wave_read:
2223
def __init__(self, f: _File) -> None: ...
2324
if sys.version_info >= (3, 0):

0 commit comments

Comments
 (0)