This commit adds a few missing return types to the Python 3 textwrap
stubs and fleshes out the Python 2 textwrap stubs so they're on par with
the Python 3 version.
This change:
1. Changes the order of the arguments in Python 2 and Python 3
to match the order from the source code instead of the
documentation.
2. Adds other undocumented attributes besides whitespace_trans
(for consistency).
3. Moves the '*' argument in TextWrapper.__init__ for Python 3
to match the source code.
4. Made function stub formatting consistent with typeshed style
conventions.
Turns out that pytype is a bit more finicky about imports, and
differentiates between '*' imports for export, and imports
for use in the local pyi. This adjusts ast.pyi to make pytype
understand it again.
After mypy [started hiding](https://github.com/python/mypy/pull/3706) imported names in stubs unless `from ... import ...` is used, we found an error with stubs of ast module.
It looks like ast module should re-export everything in `_ast` and according to PEP 484, it can do that by doing `from _ast import *`, so this is what this PR does.
These stubs are identical in Python 2 and 3, but I believe they
should not be merged, because there are numerous other modules
in the encodings package, and some only exist in some Python
versions. I don't think we can support that in the 2and3
directory.
posixpath.pyi did a '*' import of genericpath.pyi and then redefined
everything it imported. Removes the duplicate definitions from posixpath
and improves the ones in genericpath.
* os: merge the top and bottom of os/__init__.pyi
Part of #1427. In preparation for merging the two stubs, I'm making the files
identical as much as possible. This PR merges the top of the file, down to
but not including the definition of statvfs_result, and the bottom up to
and including os.utime.
This PR mostly adds more "if sys.version_info" block. Until the merger
completes, we'll have some Python 2 blocks in the Python 3 stub and vice versa.
I also add a few missing constants and arguments.
In followup PRs I'll merge the rest of the file. I'll put the trickiest part
(the return values of functions like os.stat) in its own PR.
* back out DirEntry from py2
It relies on stat_result which we don't have yet in py2.
* urlparse: allow unicode arguments in more places
Part of #1411
urlunsplit() and similar functions accept either unicode or str in all
places. Their actual return type is unicode if any of the arguments is
unicode and nonempty, which the type system can't exactly express. I
left the return type as str because str is implicitly promoted to
unicode, so using the return type in a place that accepts unicode should
work.
unquote, parse_qs, and parse_qsl return unicode if you pass them unicode,
so AnyStr is appropriate in their stubs.
* fix type for urldefrag
The return type was wrong; this function returns a 2-tuple. The second member of the tuple is always a `str` if the argument type does not contain '#', and otherwise matches the type of the argument.
* make io.pyi import _io.py(i), like io.py does
* make write/writelines take 'Any', on _IOBase
* Add missing constructors, fix inconsistencies.
* Also, as far as possible, try to simplify, by moving methods into base
classes.
* fix lint+mypy warnings
* add missing __enter__ methods
* make _IOBase inherit from BinaryIO
* make _TextIOBase not subclass _IOBase