Skip to content

Commit e3889c7

Browse files
authored
pep 484: explicit reexport as intended (#4586)
See discussion on typing-sig. This doesn't take care of some third_party libraries, will follow up on those. Co-authored-by: hauntsaninja <>
1 parent 27dfbf6 commit e3889c7

File tree

13 files changed

+76
-30
lines changed

13 files changed

+76
-30
lines changed

stdlib/2/collections.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# These are not exported.
22
# These are exported.
33
from typing import (
4-
AbstractSet as Set,
4+
AbstractSet,
55
Any,
66
Callable as Callable,
77
Container as Container,
@@ -30,6 +30,8 @@ from typing import (
3030
overload,
3131
)
3232

33+
Set = AbstractSet
34+
3335
_S = TypeVar("_S")
3436
_T = TypeVar("_T")
3537
_KT = TypeVar("_KT")

stdlib/2/future_builtins.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
from itertools import ifilter as filter, imap as map, izip as zip
1+
from itertools import ifilter, imap, izip
22
from typing import Any
33

4+
filter = ifilter
5+
map = imap
6+
zip = izip
7+
48
def ascii(obj: Any) -> str: ...
59
def hex(x: int) -> str: ...
610
def oct(x: int) -> str: ...

stdlib/2/md5.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Stubs for Python 2.7 md5 stdlib module
22

3-
from hashlib import md5 as md5, md5 as new
3+
from hashlib import md5 as md5
44

5+
new = md5
56
blocksize: int
67
digest_size: int

stdlib/2/os/__init__.pyi

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22
from _typeshed import AnyPath, FileDescriptorLike
3-
from builtins import OSError as error
3+
from builtins import OSError
44
from io import TextIOWrapper as _TextIOWrapper
55
from posix import listdir as listdir, stat_result as stat_result # TODO: use this, see https://github.com/python/mypy/issues/3078
66
from typing import (
@@ -35,6 +35,8 @@ _T = TypeVar("_T")
3535

3636
# ----- os variables -----
3737

38+
error = OSError
39+
3840
if sys.version_info >= (3, 2):
3941
supports_bytes_environ: bool
4042

@@ -152,7 +154,9 @@ TMP_MAX: int # Undocumented, but used by tempfile
152154

153155
# ----- os classes (structures) -----
154156
if sys.version_info >= (3, 6):
155-
from builtins import _PathLike as PathLike # See comment in builtins
157+
from builtins import _PathLike
158+
159+
PathLike = _PathLike # See comment in builtins
156160

157161
class _StatVFS(NamedTuple):
158162
f_bsize: int

stdlib/2and3/_dummy_threading.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,11 @@ class Event:
155155
def wait(self, timeout: Optional[float] = ...) -> bool: ...
156156

157157
if sys.version_info >= (3, 8):
158-
from _thread import ExceptHookArgs as _ExceptHookArgs, _ExceptHookArgs as ExceptHookArgs # don't ask
158+
import _thread
159+
160+
# don't ask...
161+
_ExceptHookArgs = _thread.ExceptHookArgs
162+
ExceptHookArgs = _thread._ExceptHookArgs
159163

160164
excepthook: Callable[[_ExceptHookArgs], Any]
161165

stdlib/2and3/threading.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,11 @@ class Event:
155155
def wait(self, timeout: Optional[float] = ...) -> bool: ...
156156

157157
if sys.version_info >= (3, 8):
158-
from _thread import ExceptHookArgs as _ExceptHookArgs, _ExceptHookArgs as ExceptHookArgs # don't ask
158+
import _thread
159+
160+
# don't ask...
161+
_ExceptHookArgs = _thread.ExceptHookArgs
162+
ExceptHookArgs = _thread._ExceptHookArgs
159163

160164
excepthook: Callable[[_ExceptHookArgs], Any]
161165

stdlib/3/collections/__init__.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
22
import typing
33
from typing import (
4-
AbstractSet as Set,
4+
AbstractSet,
55
Any,
66
AsyncIterable as AsyncIterable,
77
AsyncIterator as AsyncIterator,
@@ -36,6 +36,8 @@ from typing import (
3636
overload,
3737
)
3838

39+
Set = AbstractSet
40+
3941
if sys.version_info >= (3, 6):
4042
from typing import AsyncGenerator as AsyncGenerator, Collection as Collection
4143

stdlib/3/os/__init__.pyi

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ from _typeshed import (
88
OpenBinaryModeWriting,
99
OpenTextMode,
1010
)
11-
from builtins import OSError as error
11+
from builtins import OSError
1212
from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper as _TextIOWrapper
1313
from posix import listdir as listdir, times_result
1414
from typing import (
@@ -46,6 +46,8 @@ _T = TypeVar("_T")
4646

4747
# ----- os variables -----
4848

49+
error = OSError
50+
4951
supports_bytes_environ: bool
5052

5153
supports_dir_fd: Set[Callable[..., Any]]
@@ -268,7 +270,9 @@ class stat_result:
268270
st_type: int
269271

270272
if sys.version_info >= (3, 6):
271-
from builtins import _PathLike as PathLike # See comment in builtins
273+
from builtins import _PathLike
274+
275+
PathLike = _PathLike # See comment in builtins
272276

273277
_FdOrAnyPath = Union[int, AnyPath]
274278

stdlib/3/platform.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import sys
44

55
if sys.version_info < (3, 9):
6-
from os import devnull as DEV_NULL
6+
import os
7+
8+
DEV_NULL = os.devnull
79
from typing import NamedTuple, Optional, Tuple
810

911
if sys.version_info >= (3, 8):

third_party/2/six/__init__.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import typing
55
import unittest
66
from __builtin__ import unichr as unichr
77
from functools import wraps as wraps
8-
from StringIO import StringIO as BytesIO, StringIO as StringIO
8+
from StringIO import StringIO as StringIO
99
from typing import (
1010
Any,
1111
AnyStr,
@@ -29,6 +29,8 @@ from typing import (
2929

3030
from . import moves
3131

32+
BytesIO = StringIO
33+
3234
_T = TypeVar("_T")
3335
_K = TypeVar("_K")
3436
_V = TypeVar("_V")

third_party/2/six/moves/__init__.pyi

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,12 @@
22
#
33
# Note: Commented out items means they weren't implemented at the time.
44
# Uncomment them when the modules have been added to the typeshed.
5-
import __builtin__ as builtins
6-
from __builtin__ import (
7-
intern as intern,
8-
raw_input as input,
9-
reduce as reduce,
10-
reload as reload_module,
11-
xrange as range,
12-
xrange as xrange,
13-
)
14-
from cStringIO import StringIO as cStringIO
15-
from itertools import ifilter as filter, ifilterfalse as filterfalse, imap as map, izip as zip, izip_longest as zip_longest
16-
from os import getcwd as getcwdb, getcwdu as getcwd
17-
from pipes import quote as shlex_quote
5+
import __builtin__
6+
import itertools
7+
import os
8+
import pipes
9+
from __builtin__ import intern as intern, reduce as reduce, xrange as xrange
10+
from cStringIO import StringIO as _cStringIO
1811
from StringIO import StringIO as StringIO
1912
from UserDict import UserDict as UserDict
2013
from UserList import UserList as UserList
@@ -65,3 +58,21 @@ from . import (
6558
)
6659

6760
# import SimpleXMLRPCServer as xmlrpc_server
61+
62+
builtins = __builtin__
63+
input = __builtin__.raw_input
64+
reload_module = __builtin__.reload
65+
range = __builtin__.xrange
66+
67+
cStringIO = _cStringIO
68+
69+
filter = itertools.ifilter
70+
filterfalse = itertools.ifilterfalse
71+
map = itertools.imap
72+
zip = itertools.izip
73+
zip_longest = itertools.izip_longest
74+
75+
getcwdb = os.getcwd
76+
getcwd = os.getcwdu
77+
78+
shlex_quote = pipes.quote

third_party/2/six/moves/urllib/parse.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ from urllib import (
66
splittag as splittag,
77
splituser as splituser,
88
unquote as unquote,
9-
unquote as unquote_to_bytes,
109
unquote_plus as unquote_plus,
1110
urlencode as urlencode,
1211
)
@@ -27,3 +26,5 @@ from urlparse import (
2726
uses_query as uses_query,
2827
uses_relative as uses_relative,
2928
)
29+
30+
unquote_to_bytes = unquote

third_party/3/six/moves/__init__.pyi

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
#
33
# Note: Commented out items means they weren't implemented at the time.
44
# Uncomment them when the modules have been added to the typeshed.
5-
from builtins import filter as filter, input as input, map as map, range as range, range as xrange, zip as zip
5+
import importlib
6+
import shlex
7+
from builtins import filter as filter, input as input, map as map, range as range, zip as zip
68
from collections import UserDict as UserDict, UserList as UserList, UserString as UserString
79
from functools import reduce as reduce
8-
from importlib import reload as reload_module
9-
from io import StringIO as StringIO, StringIO as cStringIO
10+
from io import StringIO as StringIO
1011
from itertools import filterfalse as filterfalse, zip_longest as zip_longest
1112
from os import getcwd as getcwd, getcwdb as getcwdb
12-
from shlex import quote as shlex_quote
1313
from sys import intern as intern
1414

1515
# import tkinter.font as tkinter_font
@@ -58,3 +58,8 @@ from . import (
5858

5959
# import xmlrpc.client as xmlrpc_client
6060
# import xmlrpc.server as xmlrpc_server
61+
62+
xrange = range
63+
reload_module = importlib.reload
64+
cStringIO = StringIO
65+
shlex_quote = shlex.quote

0 commit comments

Comments
 (0)