Skip to content

Commit 0142a87

Browse files
adjust isort config (#4290)
Fixes #4288. - Default imports to THIRD_PARTY, so in effect we merge the FIRST_PARTY and THIRD_PARTY stubs. This means import order is no longer affected by whether typing_extensions is installed locally. - Treat typing_extensions, _typeshed and some others as standard library modules. Note that isort master is very different from the latest release; we'll have to do something different if and when the next isort release comes out.
1 parent cc8344b commit 0142a87

File tree

113 files changed

+106
-228
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+106
-228
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ jobs:
3232
- name: "black"
3333
install: pip install $(grep black requirements-tests-py3.txt)
3434
script: black --check --diff stdlib third_party
35-
allow_failures:
3635
- name: "isort"
3736
install: pip install $(grep isort requirements-tests-py3.txt)
3837
script: isort --check-only --diff --recursive stdlib third_party

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ force_grid_wrap = 0
99
use_parentheses = true
1010
combine_as_imports = true
1111
line_length = 130
12+
default_section = "THIRDPARTY"
13+
known_standard_library = ["typing_extensions", "_typeshed", "_compression", "_markupbase", "opcode"]

stdlib/2/ConfigParser.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from typing import IO, Any, Dict, List, Optional, Sequence, Tuple, Union
2-
31
from _typeshed import SupportsReadline
2+
from typing import IO, Any, Dict, List, Optional, Sequence, Tuple, Union
43

54
DEFAULTSECT: str
65
MAX_INTERPOLATION_DEPTH: int

stdlib/2/__builtin__.pyi

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
# Python 3, and stub files conform to Python 3 syntax.
33

44
import sys
5+
from _typeshed import (
6+
AnyPath,
7+
OpenBinaryMode,
8+
OpenBinaryModeReading,
9+
OpenBinaryModeUpdating,
10+
OpenBinaryModeWriting,
11+
OpenTextMode,
12+
ReadableBuffer,
13+
SupportsWrite,
14+
)
515
from abc import ABCMeta
616
from ast import AST, mod
717
from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper
@@ -46,20 +56,8 @@ from typing import (
4656
ValuesView,
4757
overload,
4858
)
49-
5059
from typing_extensions import Literal
5160

52-
from _typeshed import (
53-
AnyPath,
54-
OpenBinaryMode,
55-
OpenBinaryModeReading,
56-
OpenBinaryModeUpdating,
57-
OpenBinaryModeWriting,
58-
OpenTextMode,
59-
ReadableBuffer,
60-
SupportsWrite,
61-
)
62-
6361
if sys.version_info >= (3,):
6462
from typing import SupportsBytes, SupportsRound
6563

stdlib/2/compileall.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from typing import Any, Optional, Pattern
2-
31
from _typeshed import AnyPath
2+
from typing import Any, Optional, Pattern
43

54
# rx can be any object with a 'search' method; once we have Protocols we can change the type
65
def compile_dir(

stdlib/2/fcntl.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from typing import Any, Union
2-
31
from _typeshed import FileDescriptorLike
2+
from typing import Any, Union
43

54
FASYNC: int
65
FD_CLOEXEC: int

stdlib/2/json.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from typing import IO, Any, Callable, Dict, List, Optional, Text, Tuple, Type, Union
2-
31
from _typeshed import SupportsRead
2+
from typing import IO, Any, Callable, Dict, List, Optional, Text, Tuple, Type, Union
43

54
class JSONDecodeError(ValueError):
65
def dumps(self, obj: Any) -> str: ...

stdlib/2/os/__init__.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sys
2+
from _typeshed import AnyPath
23
from builtins import OSError as error
34
from io import TextIOWrapper as _TextIOWrapper
45
from posix import listdir as listdir, stat_result as stat_result # TODO: use this, see https://github.com/python/mypy/issues/3078
@@ -25,8 +26,6 @@ from typing import (
2526
overload,
2627
)
2728

28-
from _typeshed import AnyPath
29-
3029
from . import path as path
3130

3231
# We need to use something from path, or flake8 and pytype get unhappy

stdlib/2/os/path.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# NB: path.pyi and stdlib/2 and stdlib/3 must remain consistent!
22
import os
33
import sys
4+
from _typeshed import AnyPath, BytesPath, StrPath
45
from genericpath import exists as exists
56
from typing import Any, AnyStr, Callable, List, Optional, Sequence, Text, Tuple, TypeVar, overload
67

7-
from _typeshed import AnyPath, BytesPath, StrPath
8-
98
_T = TypeVar("_T")
109

1110
if sys.version_info >= (3, 6):

stdlib/2/os2emxpath.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# NB: path.pyi and stdlib/2 and stdlib/3 must remain consistent!
22
import os
33
import sys
4+
from _typeshed import AnyPath, BytesPath, StrPath
45
from genericpath import exists as exists
56
from typing import Any, AnyStr, Callable, List, Optional, Sequence, Text, Tuple, TypeVar, overload
67

7-
from _typeshed import AnyPath, BytesPath, StrPath
8-
98
_T = TypeVar("_T")
109

1110
if sys.version_info >= (3, 6):

stdlib/2and3/_typeshed/__init__.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import array
1616
import mmap
1717
import sys
1818
from typing import Protocol, Text, TypeVar, Union
19-
2019
from typing_extensions import Literal
2120

2221
_T_co = TypeVar("_T_co", covariant=True)

stdlib/2and3/aifc.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import sys
22
from types import TracebackType
33
from typing import IO, Any, List, NamedTuple, Optional, Text, Tuple, Type, Union, overload
4-
54
from typing_extensions import Literal
65

76
class Error(Exception): ...

stdlib/2and3/array.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import sys
66
from typing import Any, BinaryIO, Generic, Iterable, Iterator, List, MutableSequence, Text, Tuple, TypeVar, Union, overload
7-
87
from typing_extensions import Literal
98

109
_IntTypeCode = Literal["b", "B", "h", "H", "i", "I", "l", "L", "q", "Q"]

stdlib/2and3/asyncore.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import sys
2+
from _typeshed import FileDescriptorLike
23
from socket import SocketType
34
from typing import Any, Dict, Optional, Tuple, Union, overload
45

5-
from _typeshed import FileDescriptorLike
6-
76
# cyclic dependence with asynchat
87
_maptype = Dict[int, Any]
98

stdlib/2and3/builtins.pyi

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
# Python 3, and stub files conform to Python 3 syntax.
33

44
import sys
5+
from _typeshed import (
6+
AnyPath,
7+
OpenBinaryMode,
8+
OpenBinaryModeReading,
9+
OpenBinaryModeUpdating,
10+
OpenBinaryModeWriting,
11+
OpenTextMode,
12+
ReadableBuffer,
13+
SupportsWrite,
14+
)
515
from abc import ABCMeta
616
from ast import AST, mod
717
from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper
@@ -46,20 +56,8 @@ from typing import (
4656
ValuesView,
4757
overload,
4858
)
49-
5059
from typing_extensions import Literal
5160

52-
from _typeshed import (
53-
AnyPath,
54-
OpenBinaryMode,
55-
OpenBinaryModeReading,
56-
OpenBinaryModeUpdating,
57-
OpenBinaryModeWriting,
58-
OpenTextMode,
59-
ReadableBuffer,
60-
SupportsWrite,
61-
)
62-
6361
if sys.version_info >= (3,):
6462
from typing import SupportsBytes, SupportsRound
6563

stdlib/2and3/bz2.pyi

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import io
22
import sys
3+
from _typeshed import AnyPath
34
from typing import IO, Any, Optional, TextIO, TypeVar, Union, overload
4-
55
from typing_extensions import Literal
66

7-
from _typeshed import AnyPath
8-
97
_PathOrFile = Union[AnyPath, IO[bytes]]
108
_T = TypeVar("_T")
119

stdlib/2and3/cProfile.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import sys
2-
from typing import Any, Callable, Dict, Optional, TypeVar, Union
3-
42
from _typeshed import AnyPath
3+
from typing import Any, Callable, Dict, Optional, TypeVar, Union
54

65
def run(statement: str, filename: Optional[str] = ..., sort: Union[str, int] = ...) -> None: ...
76
def runctx(

stdlib/2and3/cgitb.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
from _typeshed import AnyPath
12
from types import FrameType, TracebackType
23
from typing import IO, Any, Callable, Dict, List, Optional, Tuple, Type
34

4-
from _typeshed import AnyPath
5-
65
_ExcInfo = Tuple[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]]
76

87
def reset() -> str: ... # undocumented

stdlib/2and3/codecs.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ from typing import (
2020
Union,
2121
overload,
2222
)
23-
2423
from typing_extensions import Literal
2524

2625
# TODO: this only satisfies the most common interface, where

stdlib/2and3/fileinput.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import sys
2-
from typing import IO, Any, AnyStr, Callable, Generic, Iterable, Iterator, Optional, Union
3-
42
from _typeshed import AnyPath
3+
from typing import IO, Any, AnyStr, Callable, Generic, Iterable, Iterator, Optional, Union
54

65
if sys.version_info >= (3, 8):
76
def input(

stdlib/2and3/ftplib.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sys
2+
from _typeshed import SupportsRead, SupportsReadline
23
from socket import socket
34
from ssl import SSLContext
45
from types import TracebackType
@@ -20,8 +21,6 @@ from typing import (
2021
Union,
2122
)
2223

23-
from _typeshed import SupportsRead, SupportsReadline
24-
2524
_T = TypeVar("_T")
2625
_IntOrStr = Union[int, Text]
2726

stdlib/2and3/hmac.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# Stubs for hmac
22

33
import sys
4+
from _typeshed import ReadableBuffer
45
from types import ModuleType
56
from typing import Any, AnyStr, Callable, Optional, Union, overload
67

7-
from _typeshed import ReadableBuffer
8-
98
_B = Union[bytes, bytearray]
109

1110
# TODO more precise type for object of hashlib

stdlib/2and3/imaplib.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import time
44
from socket import socket as _socket
55
from ssl import SSLContext, SSLSocket
66
from typing import IO, Any, Callable, Dict, List, Optional, Pattern, Text, Tuple, Type, Union
7-
87
from typing_extensions import Literal
98

109
# TODO: Commands should use their actual return types, not this type alias.

stdlib/2and3/lib2to3/pgen2/driver.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1+
from _typeshed import StrPath
12
from lib2to3.pgen2.grammar import Grammar
23
from lib2to3.pytree import _NL, _Convert
34
from logging import Logger
45
from typing import IO, Any, Iterable, Optional, Text
56

6-
from _typeshed import StrPath
7-
87
class Driver:
98
grammar: Grammar
109
logger: Logger

stdlib/2and3/lib2to3/pgen2/grammar.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from typing import Dict, List, Optional, Text, Tuple, TypeVar
2-
31
from _typeshed import StrPath
2+
from typing import Dict, List, Optional, Text, Tuple, TypeVar
43

54
_P = TypeVar("_P")
65
_Label = Tuple[int, Optional[Text]]

stdlib/2and3/lib2to3/pgen2/pgen.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
from _typeshed import StrPath
12
from lib2to3.pgen2 import grammar
23
from lib2to3.pgen2.tokenize import _TokenInfo
34
from typing import IO, Any, Dict, Iterable, Iterator, List, NoReturn, Optional, Text, Tuple
45

5-
from _typeshed import StrPath
6-
76
class PgenGrammar(grammar.Grammar): ...
87

98
class ParserGenerator:

stdlib/2and3/logging/__init__.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import sys
22
import threading
3+
from _typeshed import StrPath
34
from string import Template
45
from time import struct_time
56
from types import FrameType, TracebackType
@@ -20,8 +21,6 @@ from typing import (
2021
overload,
2122
)
2223

23-
from _typeshed import StrPath
24-
2524
_SysExcInfoType = Union[Tuple[type, BaseException, Optional[TracebackType]], Tuple[None, None, None]]
2625
if sys.version_info >= (3, 5):
2726
_ExcInfoType = Union[None, bool, _SysExcInfoType, BaseException]

stdlib/2and3/logging/config.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import sys
2+
from _typeshed import AnyPath, StrPath
23
from threading import Thread
34
from typing import IO, Any, Callable, Dict, Optional, Union
45

5-
from _typeshed import AnyPath, StrPath
6-
76
if sys.version_info >= (3,):
87
from configparser import RawConfigParser
98
else:

stdlib/2and3/logging/handlers.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import datetime
22
import ssl
33
import sys
4+
from _typeshed import StrPath
45
from logging import FileHandler, Handler, LogRecord
56
from socket import SocketType
67
from typing import Any, Callable, Dict, List, Optional, Tuple, Union, overload
78

8-
from _typeshed import StrPath
9-
109
if sys.version_info >= (3, 7):
1110
from queue import SimpleQueue, Queue
1211
elif sys.version_info >= (3,):

stdlib/2and3/macpath.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33

44
import os
55
import sys
6-
from typing import Any, AnyStr, Callable, List, Optional, Sequence, Text, Tuple, TypeVar, Union, overload
7-
86
from _typeshed import AnyPath, BytesPath, StrPath
7+
from typing import Any, AnyStr, Callable, List, Optional, Sequence, Text, Tuple, TypeVar, Union, overload
98

109
if sys.version_info < (3, 8):
1110
_T = TypeVar("_T")

stdlib/2and3/mailbox.pyi

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import email
2+
from _typeshed import AnyPath
23
from types import TracebackType
34
from typing import (
45
IO,
@@ -21,11 +22,8 @@ from typing import (
2122
Union,
2223
overload,
2324
)
24-
2525
from typing_extensions import Literal
2626

27-
from _typeshed import AnyPath
28-
2927
_T = TypeVar("_T")
3028
_MessageType = TypeVar("_MessageType", bound=Message)
3129
_MessageData = Union[email.message.Message, bytes, str, IO[str], IO[bytes]]

stdlib/2and3/mmap.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import sys
2-
from typing import AnyStr, ContextManager, Generic, Iterable, Iterator, Optional, Sequence, Sized, Union, overload
3-
42
from _typeshed import ReadableBuffer
3+
from typing import AnyStr, ContextManager, Generic, Iterable, Iterator, Optional, Sequence, Sized, Union, overload
54

65
ACCESS_DEFAULT: int
76
ACCESS_READ: int

0 commit comments

Comments
 (0)