Commit Graph

2162 Commits

Author SHA1 Message Date
Sebastian Rittau
187aaaced9 Use protocols for shutils.copyfileobj() (#2291)
See https://github.com/python/typing/issues/564 for background.
2018-06-28 10:28:24 -07:00
Sebastian Rittau
7ebd609643 Add pyexpat and xml.parsers (#2276) 2018-06-28 10:26:17 -07:00
potykion
f35c5d1349 Jinja2 async support (#2278) 2018-06-28 10:24:37 -07:00
Sebastian Rittau
b261b228ba Merge Python 2 and 3 shutil (#2259)
* Drop support for Python 3.3
* Merge Python 2 and 3 shutil
* Marked some arguments optional
* Changed callback return type from None to Any for more flexibility
2018-06-27 20:42:58 -07:00
Yusuke Miyazaki
86883d3df9 Remove unused import statements (#2282) 2018-06-27 20:14:57 -07:00
Philipp Hahn
f8041d08db logging.BASIC_FORMAT also for python2.7 (#2283) 2018-06-27 20:14:06 -07:00
Philipp Hahn
ee07115c96 urllib2.build_open() accepts instances and classes (#2284)
<https://docs.python.org/2/library/urllib2.html#urllib2.build_opener>
> handlers can be either instances of BaseHandler, or subclasses of
> BaseHandler (in which case it must be possible to call the constructor
> without any parameters).
2018-06-27 20:13:46 -07:00
Philipp Hahn
4e3b8f7e15 tty.set*() accepts fd or file object (#2285)
<https://docs.python.org/2/library/tty.html>
> ... requires the termios module ...

<https://docs.python.org/2/library/termios.html#module-termios>
> All functions in this module take a file descriptor fd as their first
> argument. This can be an integer file descriptor ... or a file object,
2018-06-27 20:12:04 -07:00
Nipunn Koorapati
b7df5a670a Add type stubs for google.protobuf.service (#2187) 2018-06-27 15:38:29 -07:00
Guido van Rossum
5b32e79f4a [gflags] Give DEFINE* default values Optional types (#2279)
I found some code that called DEFINE_integer() and DEFINE_float() with default set to None. Perusing the code that seems to be a totally valid usage. I am not super familiar with gflags but I believe this PR consistently changes all those default values to Optional[].
2018-06-26 13:53:39 -07:00
Yusuke Miyazaki
b91cb87249 Add a convention for platform-dependent APIs to CONTRIBUTING.md (#2281) 2018-06-26 09:14:12 -07:00
Ethan Smith
de1755b263 Remove type cycle in click (#2277) 2018-06-26 07:24:55 -07:00
Guido van Rossum
41e5fe4457 Message.WhichOneof returns Text, not bytes (#2274) 2018-06-23 15:42:13 -07:00
NAKAMURA Yoshitaka
16ed540c95 Fix type for imaplib.IMAP4.error and related (#2273) 2018-06-22 08:43:25 -07:00
Sebastian Rittau
39d95f16cf Drop Python 3.3 support from importlib stubs (#2264) 2018-06-22 08:36:00 -07:00
Ethan Smith
507ad2dcbe importlib.util.find_spec has optional return type (#2270) 2018-06-22 08:06:06 -07:00
Sebastian Rittau
95eff73ab2 Drop Python 3.3 support from several stubs (#2265)
* Drop Python 3.3 support from several stubs

* Revert wrong socketserver changes
2018-06-20 16:49:47 -07:00
Sebastian Rittau
b05e99297c Drop Python 3.3 support from several stubs (#2266)
* Drop Python 3.3 support from importlib stubs

* Drop Python 3.3 support from html and symbol stubs
2018-06-20 16:46:11 -07:00
Sebastian Rittau
1184726417 Drop Python 3.3 support from email stubs (#2263) 2018-06-20 12:04:22 -07:00
John Reese
40b176b195 Fix annotation for difflib.SequenceMatcher.find_longest_match (#2253) 2018-06-20 10:52:39 -07:00
Michael Lee
fb92ee84c5 Make overloads in the Python 2 builtins with a 'None' fallback come first (#2261)
In short, this change makes sure calls like `map(None, a, b)` behave as
expected when using `--no-strict-optional` is enabled.

For additional context, see https://github.com/python/mypy/issues/5246
2018-06-20 08:26:06 -07:00
Sebastian Rittau
fa74160e1f Drop support for Python 3.3 (#2258)
Closes #2257.
2018-06-19 15:37:13 -07:00
Jukka Lehtosalo
07374a8251 Fix requests.post signature (#2256)
The change introduced in 395ab5abd1
broke the signature of `requests.post`, among others, since
`MutableSequence` is invariant, and plain `Dict[str, str]` values
were no longer valid for the `data` argument.

This changes the signature to have `Any` components as a
compromise. Adding more items to the union seems a bit too much, since
the error messages for invalid argument types are already pretty hard to
read.

Another option might be to use `Mapping` instead of `MutableMapping`
due to covariance, but I assume there's a reason why `MutableMapping`
is used here.
2018-06-19 17:08:55 +01:00
Jukka Lehtosalo
feeb4e71ef Change mock classes to Any values to avoid false positives (#2255)
The previous definitions in `mock` caused many false positives in
internal Dropbox repositories.

One source of problems was `List[Mock]` not being compatible with
`List[SomeClass]`, since `list` is invariant.
2018-06-19 16:28:19 +01:00
Jukka Lehtosalo
a88d942f91 Add missing protobuf container methods (#2254)
Implementation of the methods is here:

https://github.com/google/protobuf/blob/master/python/google/protobuf/internal/containers.py
2018-06-19 15:52:54 +01:00
Andrew Svetlov
a5b7ddd96c Accepy bytes in sock.connect() and family (#2252) 2018-06-18 10:30:41 -07:00
Sekou Diao
96e3e23d9b Add locale.windows (#2251)
This is undocumented but it exists (on all platforms AFAICT) and is used, so it should be added, marked `# undocumented`.
2018-06-18 09:19:55 -07:00
strager
e404bc7cd6 Allow pathlib.Path in zipfile.ZipFile (#2238)
`zipfile.ZipFile` is typed to accept `Text` for local and archive file
paths. In Python 3.6, several `ZipFile` methods accept `pathlib.Path`
objects, not just `str` objects. Generalize `ZipFile`'s methods so code
using `pathlib.Path` with `ZipFile` type-checks.

I verified (using my own project) that the following methods work with
os.PurePath at runtime on CPython 3.6:

* zipfile.ZipInfo.__init__
* zipfile.ZipInfo.extractall
* zipfile.ZipInfo.write
2018-06-18 08:29:23 -07:00
Daniel Li
1a8455b444 Add thread_name_prefix to ThreadPoolExecutor stub (#2249)
The thread_name_prefix argument of ThreadPoolExecutor.__init__ was added
to the Python 2 backport in agronholm/pythonfutures#64.
2018-06-17 18:33:37 -07:00
Jelle Zijlstra
00cda79cf5 add io.TextIOWrapper.read in 3.3 (#2248)
This is needed to make TextIOWrapper and a few classes that inherit
from it concrete in 3.3. I am actually not sure whether this method
exists at runtime; there's nothing in
https://docs.python.org/3/library/io.html#io.TextIOWrapper
that suggests it was added in 3.4. In any case, it hardly matters
since 3.3 usage should be very rare now.
2018-06-17 23:47:07 +01:00
Jelle Zijlstra
3032fbdff1 make http.client.HTTPResponse concrete in 3.4 (#2244)
Matches the implementation in https://github.com/python/cpython/blob/3.4/Lib/http/client.py#L308

The ignore works around python/mypy#5027 (commented further up in the 3.5 branch).

Part of #1476.
2018-06-17 17:29:02 +01:00
Jelle Zijlstra
da8de48f6d UserList and UserString in 2.7 (#2246)
Fill out UserList and UserString stubs to make the classes concrete. Compare:
https://github.com/python/cpython/blob/2.7/Lib/UserList.py
https://github.com/python/cpython/blob/2.7/Lib/UserString.py
2018-06-17 17:24:30 +01:00
Jelle Zijlstra
8084dc1c1f Fix abstract classes in 2.7 (#2247)
Part of #1476.
2018-06-17 17:21:17 +01:00
Jelle Zijlstra
6b36b1befe Iterator provides a concrete __iter__ in 2.7 (#2245)
This is already how it works in the Python 3 stub.

`Iterator.__iter__` also exists at runtime: https://github.com/python/cpython/blob/2.7/Lib/_abcoll.py#L73.
2018-06-17 12:00:42 +01:00
Jelle Zijlstra
0393de4bd7 fix some abstract classes in Python 2 (#2240)
Part of #1476.
2018-06-17 00:56:00 +01:00
Philipp Hahn
7c3edba6ce python2/gettext improvements (#2235)
* py2: gettext: info()

returns a Dict[str, str]

<https://docs.python.org/2/library/gettext.html#gettext.NullTranslations.info>
> Return the “protected” _info variable.

<https://docs.python.org/2/library/gettext.html#the-gnutranslations-class>
> The entire set of key/value pairs are placed into a dictionary and set
> as the “protected” _info instance variable.

* py2: gettext: charset()

returns an Optional[str]

<https://docs.python.org/2/library/gettext.html#gettext.NullTranslations.charset>
> Return the “protected” _charset variable.

<https://docs.python.org/2/library/gettext.html#the-gnutranslations-class>
> If the key Content-Type is found, then the charset property is used to
> initialize the “protected” _charset instance variable, defaulting to
> None if not found.

* py2: gettext: [set_]output_charset()

allows to set an Optional[str]

<https://docs.python.org/2/library/gettext.html#gettext.NullTranslations.output_charset>
> Return the “protected” _output_charset variable.

<https://docs.python.org/2/library/gettext.html#gettext.NullTranslations.set_output_charset>
> Change the “protected” _output_charset variable, which defines the
> encoding used to return translated messages.

<https://docs.python.org/2/library/gettext.html#gettext.GNUTranslations.lgettext>
> Equivalent to gettext(), but the translation is returned in the
> preferred system encoding, if no other encoding was explicitly set with
> set_output_charset().

* py2: gettext: install(..., names)

allows to set an Optional[str]

<https://docs.python.org/2/library/gettext.html#gettext.NullTranslations.install>
> If the names parameter is given, it must be a sequence containing the
> names of functions you want to install in the builtins namespace in
> addition to _().

* py2: gettext: localdir=None

is Optional[str]

<https://docs.python.org/2/library/gettext.html#gettext.bindtextdomain>
> If localedir is omitted or None, then the current binding for domain
> is returned.

* py2: gettext: languages=None

is Optional[Sequence[str]]

<https://docs.python.org/2/library/gettext.html#gettext.find>
> If languages is not given, then the following environment variables
> are searched: ...

* py2: gettext: codeset=None

is Optional[str]

<https://docs.python.org/2/library/gettext.html#gettext.translation>
> If provided, codeset will change the charset used to encode translated
> strings.

* py2: gettext: translation(class_=None)

is Optional[type]

<https://docs.python.org/2/library/gettext.html#gettext.translation>
> The actual class instantiated is either class_ if provided, otherwise
> GNUTranslations.

* py2: gettext: translation(fallback)

is bool

<https://docs.python.org/2/library/gettext.html#gettext.translation>
> ..., this function raises IOError if fallback is false (which is the
> default), and returns a NullTranslations instance if fallback is true.

* py2: gettext: install(unicode)

is bool

<https://docs.python.org/2/library/gettext.html#gettext.install>
> The unicode flag is passed to the resulting translation object’s
> install() method.

which is already expecting `bool`.
2018-06-16 10:19:24 -07:00
Jelle Zijlstra
94ab32ba59 Fix abstract classes for Python 3 (#2239)
* add metaclass=ABCMeta to some classes

* mark some more classes as explicitly abstract

* make some more classes concrete
2018-06-16 10:18:54 -07:00
Jelle Zijlstra
341fa375ef cleanup in typing.pyi (#2241)
- Fix TODOs around TracebackType
- Don't use quotes for forward references
- Make Generator and AsyncGenerator attributes into properties
2018-06-16 08:24:52 -07:00
Jelle Zijlstra
c06a718c5b always run mypy with --no-implicit-optional (#2242)
This was already the configuration in Travis and it's been working fine. It's
confusing that Travis was using a different configuration than the default
when you run tests/mypy_test.py yourself.
2018-06-15 21:34:14 -07:00
Jelle Zijlstra
499f852e37 add --show-traceback to mypy_test.py flags (#2236)
This makes debugging easier.
2018-06-15 16:46:59 -07:00
Daniel Li
5054465746 Make concurrent.futures stubs identical (#2237)
Make the Python 2 and 3 concurrent.futures stubs identical so fixes get
applied to both.

For example, #1305 and #2233 fixed the same problem at different times,
as did #1078 and #1911.

By making the stubs identical, we apply the fix from #1711 to Python 2.

Fixes #2234.
2018-06-15 10:03:19 -07:00
Daniel Li
a9366df7e8 Improve signatures in concurrent.futures backport (#2233)
Use parameterized types in Future.add_done_callback(), wait(), and
as_completed().

Mark the traceback argument to Future.set_exception_info() as optional.
2018-06-15 08:21:01 -07:00
Anthony Sottile
56c93c85c0 Add NoReturn to execv* family of functions (#2226) 2018-06-15 07:55:45 -07:00
Rebecca Chen
ff821f9751 Update pytype_test and pytype_blacklist (#2225)
* Add parts of third_party/ to pytype_test.

Pytype uses six and mypy_extensions, so these pyi files should be
tested with pytype.

* Remove newly loadable pyi files from pytype_blacklist.
2018-06-15 07:53:17 -07:00
Jason Fried
451deba4ef memoryview type information inconsistent with runtime behavior (#2230)
memoryview type information inconsistent with documentation of typing module. 

`memoryview` should be a ByteString like the docs say. 
`memoryview.__init__` does not accept str, and instead of a union it should just accept ByteString. 
`memoryview.__iter__` returns an Iterator[int] not bytes.
2018-06-15 07:51:56 -07:00
Anthony Sottile
395ab5abd1 Values of data are Optional (#2231) 2018-06-15 07:48:55 -07:00
Bertrand Bonnefoy-Claudet
4b5a63d10f Fix werkzeug.wrappers.BaseResponse.__init__ (#2232)
This additionally allows strings, bytearrays and string iterables to be
passed as the `response` argument of `BaseResponse` (and thus also
`Response`).

Strings and bytearrays are explicitly handled in `__init__` [1].
Strings are also featured on the Werkzeug front-page snippet (`'Hello
World!'`) [2].

[1]: d129d17066/werkzeug/wrappers.py (L861)
[2]: http://werkzeug.pocoo.org/
2018-06-15 07:24:22 -07:00
Bertrand Bonnefoy-Claudet
15ad132393 Werkzeug stub fixes (#2229)
* Fix stub for werkzeug.exceptions.Aborter and abort

* `werkzeug.exceptions.abort` [1] was missing and is thus added here.
  It's also commonly used in Flask as `flask.abort`.
* They both always raise [2], hence the `NoReturn` return type.

[1]: http://werkzeug.pocoo.org/docs/0.14/exceptions/#werkzeug.exceptions.abort
[2]: d129d17066/werkzeug/exceptions.py (L708-L713)

* Fix stub for werkzeug.wrappers.AuthorizationMixin

The code [1] uses `@cached_property` [2], which is basically a Python
property, and optionally returns an `Authorization` [3] object.

[1]: d129d17066/werkzeug/wrappers.py (L1462-L1466)
[2]: d129d17066/werkzeug/utils.py (L35)
[3]: d129d17066/werkzeug/datastructures.py (L2438)
2018-06-14 09:04:18 -07:00
Philipp Hahn
02c42c9cf6 optparse.Values.__getattr__ like argparse.Namespace (#2228)
optparse.Values is like argparse.Namespace and also has a __getattr__() method to return the parsed options.
Apply commits 54b4983 and 9ae0c0b from python/typeshed#25
2018-06-14 06:13:10 -07:00
Anthony Sottile
be3c43cf63 A Thread(target=...) function can return anything (#2224) 2018-06-13 11:50:17 -07:00