Commit Graph

946 Commits

Author SHA1 Message Date
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
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
Anthony Sottile
56c93c85c0 Add NoReturn to execv* family of functions (#2226) 2018-06-15 07:55:45 -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
Jelle Zijlstra
de86f15fa0 Make http.client.HTTPResponse a BinaryIO (#2218)
Fixes #2189.

The errors from mypy are a false positive (see python/mypy#5027).
2018-06-12 09:20:24 -07:00
Jelle Zijlstra
6bbf3d89eb Further improve codecs stubs (#2217)
- remove header comments
- uppercase type aliases
- remove old-style type annotations
- unquote forward refs
- reformat the file
- remove values for globals
- don't use private names from codecs stub in io.pyi
2018-06-11 22:24:34 -07:00
Jelle Zijlstra
d2469c0e89 fix type for itertools.product (#2129)
Fixes #1850.

The fix was already applied to Python 2, but the typevar-based solution there
leads to "cannot infer value of type variable" in mypy. I used the following
script to check:

```python
from itertools import product

reveal_type(product([1]))
reveal_type(product([1], ['x'], [False], [3.0], [(1,)], [('x',)], [{1}], [{1: 2}], repeat=5))
```
2018-06-11 15:52:44 -07:00
Jelle Zijlstra
ced5d61bb6 make urllib.response.addinfourl instantiable (#2134)
Fixes #1377 (because HTTPError is a subclass of addinfourl). Also part of #1476.
2018-06-11 15:43:53 -07:00
Jelle Zijlstra
4e6af84640 improve multiprocessing.Pool types (#2126)
Fixes #1703

Mostly introduce typevars to express that the return types match the return types of the
callbacks.

Removed comment about incompleteness since all documented classes from
https://docs.python.org/3/library/multiprocessing.html#module-multiprocessing.pool
are covered.
2018-06-11 14:42:57 -07:00
Jelle Zijlstra
f5a74fd5da remove Optional from type of __slots__ (#2128)
Fixes #1853
2018-06-11 14:29:11 -07:00
Jelle Zijlstra
cb293ebd2e switch order of base classes on awaitable classes (#2125)
Fixes #1940.

This makes it so that mypy will infer the common base class of these
classes to be Awaitable instead of Iterable. I verified that this
fixes the errors in the script posted by @neilconway.
2018-06-11 14:20:31 -07:00
Jelle Zijlstra
7abcd0f71f add ConfigParser.readfp in Python 3 (#2123)
https://docs.python.org/3/library/configparser.html#configparser.ConfigParser.readfp

Fixes #2112
2018-06-11 14:10:52 -07:00
Jelle Zijlstra
53fde2ddf7 make timeout argument to Connection.poll Optional (#2122)
Fixes #2094
2018-06-11 14:04:45 -07:00
Jelle Zijlstra
91af6291b1 make shlex.shlex and multiprocessing.pool.IMapIterator instantiable (#2120)
Part of #1476.
2018-06-11 14:04:05 -07:00
Jelle Zijlstra
28f6c095d4 make http.cookies.{Base,Simple}Cookie instantiable (#2116)
Part of #1476.
2018-06-11 14:01:17 -07:00
Jelle Zijlstra
38fb53eab6 add __init__ to SimpleNamespace (#2207)
```In [11]: SimpleNamespace(x=3)
Out[11]: namespace(x=3)
```
2018-06-11 08:08:41 -07:00
Daniel Li
87c296c964 Some inspect.formatargspec args cannot be None (#2212)
The annotations, formatarg, formatvarargs, formatvarkw, formatvalue,
formatreturns, and formatannotations arguments to inspect.formatargspec
have default values, but they cannot be None.
2018-06-11 08:07:47 -07:00
Guido van Rossum
af3b015aa8 mock.patch.object() attribute arg should be Text (#2210)
It works and is needed for code using the dreaded
'from __future__ import unicode_literals'.
2018-06-09 22:36:24 -07:00
Ethan Smith
7831f8d883 Add _winapi stub (#2209)
This module is going to be used by mypy for the daemon on Windows. To that end I ran stubgen on _winapi, then read through Modules/_winapi.c to add the function types. This seems to have been added in Python 3.1, but I think it is completely fine to just leave it in stdlib/3.
2018-06-09 18:48:30 -07:00
mbarkhau
8d852c3785 3.6+ Updates for ast module (#2208)
Added AnnAssign
Added comprehension.is_async
Fixed typo on FormattedValue.format_spec
2018-06-09 10:30:39 -07:00
mbarkhau
d7067fb287 Add FormattedValue and JoinedStr to ast for py3.6+ (#2206)
Fixes #2205

For reference https://docs.python.org/3/library/ast.html#abstract-grammar
2018-06-08 19:13:17 -07:00
Max R
34b926008e Remove Python 3.3 check in mock.pyi (#2201) 2018-06-05 15:30:28 -07:00
Froger David
ffba2ea87a compile builtin accept PathLike (#2200) 2018-06-05 14:02:46 -07:00
Froger David
ae91695fb7 Inspect (#2178)
* add inspect.{isasyncgenfunction,isasyncgen} (3.6)

* reorder inspect.CO_* as in Python 3.6 doc

* add inspect.CO_{COROUTINE,ITERABLE_COROUTINE} (3.5)

* add inspect.CO_ASYNC_GENERATOR (3.6)

* use variable annotations

* use version checks

* Parameter.empty is a class attribute

* Signature.empty is a class attribute
2018-06-05 09:59:09 -07:00
Anthony Sottile
270fba2e4e Add headers attribute to HTTPResponse (#2190) 2018-06-05 08:11:12 -07:00
Michael Hirsch, Ph.D
48904699ec urlretrieve can accept filename: pathlib.Path for Python>=3.6 (#2194) 2018-06-05 07:58:39 -07:00
Jelle Zijlstra
eef0b1d562 fix type for TestCase.assertIn (#2186)
* fix type for TestCase.assertIn

This does essentially `assert member in container`, so we want a `Container`, not an `Iterable`.

This came up in 68e9d426a8..0bbee43d60 (r192525658).

* use any for assertIn
2018-06-04 15:34:09 -07:00
Hanaasagi
7faa41984b Closes python/mypy/#5141 (#2191) 2018-06-03 21:52:19 -07:00
Anthony Sottile
2d4bb04ab3 json.load can also take IO[bytes] in py36+ (#2188) 2018-06-03 19:02:55 -07:00
Robert Collins
98badb6eff Fix mock patch.dict stub and add mock stub (#2173)
The dict stub was referring to an instance, not the type, leading to
__call__ being considered when using as a decorator, rather than
__init__.

mock is a backport of the stdlib module and should be defined the same.
2018-05-31 21:45:54 -07:00
Sebastian Rittau
a3031adb46 Merge Python 2 and 3 SSL stubs (#2175) 2018-05-31 21:44:42 -07:00
Mathieu Leduc-Hamel
351d019241 Mark inspect.getmembers as Optional for both Py2 and Py3 (#2172) 2018-05-29 10:43:34 -07:00
Sushain Cherivirala
0193ee87a8 Add OpenDirector.addheaders and PEP 526 refactoring (fixes #2163) (#2164)
* Add OpenDirector.addheaders and replace type comments with annotations

* Use ClassVar/eliminate `= ...` and add BaseHandler.handler_order (exists in Py2 versions)
2018-05-28 08:09:35 -07:00
Sushain Cherivirala
dc0fcdcaa0 Add missing signals to Py2/3; missing events to Py2; PEP 526 refactoring (fixes #1576) (#2168) 2018-05-27 22:50:10 -07:00
Michael J. Sullivan
2ba90a65c0 Remove __all__ = ... from stubs (#2161)
The presence of a __all__ causes everything to not get picked up by
import *, which among other things breaks the new six.moves stubs.
2018-05-24 19:00:07 -07:00
Michael J. Sullivan
db1316d26b os.path.relpath can use a default argument and still use str (#2159) 2018-05-24 13:23:17 -07:00
Jelle Zijlstra
b89f9553e9 keep os.path in 2 and 3 consistent (#2152)
We can't merge these because os/__init__ is still different.

Also slight refactor of tests/check_consistent.py to avoid `from os import path`.
2018-05-22 07:14:13 -07:00
Jakub Nabaglo
d84069e78d Add stub for random.Random.choices (#2156) 2018-05-21 19:38:00 -07:00
Michael Lee
709b193416 Rearrange overloads to account for optional arguments (#2150)
Basically, the same thing as [my previous pull request][0], except the
fixes are now focusing on functions with overlapping argument counts.

  [0]: https://github.com/python/typeshed/pull/2138
2018-05-19 09:20:16 -07:00
Michael Lee
97d9f2eb2c Ensures overloads are ordered from narrow to broad (#2138)
This commit reorders any overloads where the first overload was
"shadowing" the second, preventing it from ever being matched by type
checkers that work by selecting the first matching overload alternative.

For example, the first overload alternative below is strictly broader
then the second, preventing it from ever being selected:

    class Parent: pass
    class Child(Parent): pass

    @overload
    def foo(x: *int) -> Parent: ...
    @overload
    def foo(x: int, y: int) -> Child: ...

The correct thing to do is to either delete the second overload or
rearrange them to look like this:

    @overload
    def foo(x: int, y: int) -> Child: ...
    @overload
    def foo(x: *int) -> Parent: ...

Rationale: I'm currently [working on a proposal][0] that would amend
PEP 484 to (a) mandate type checkers check overloads in order and
(b) prohibit overloads where an earlier alternative completely shadows
a later one.

  [0]: https://github.com/python/typing/issues/253#issuecomment-389262904

This would prohibit overloads that look like the example below, where
the first alternative completely shadows the second.

I figured it would be a good idea to make these changes ahead of time:
if my proposal is accepted, it'd make the transition smoother. If not,
this is hopefully a relatively harmless change.

Note: I think some of these overloads could be simplified (e.g.
`reversed(...)`), but I mostly stuck with rearranging them in case I was
wrong. The only overload I actually changed was `hmac.compare_digest` --
I believe the Python 2 version actually accepts unicode.
2018-05-17 09:45:33 -04:00
Zac Hatfield-Dodds
d5929ada4d itertools.islice allows step=None (#2142) 2018-05-17 09:35:02 -04:00
Ethan Smith
e9600db2ec Remove symlinks! (#2132) 2018-05-15 15:18:59 -04:00
Jelle Zijlstra
537b97ed39 add bytearray.copy to Python 3 (#2133)
Fixes #1715.

2.7's bytearray doesn't have it.
2018-05-15 14:33:24 -04:00
Ethan Smith
db9246b3e5 Fix importlib.resources for mypy (#2130) 2018-05-15 10:34:56 -04:00
Jelle Zijlstra
55be42f6d6 add __fspath__ support to os.path (#2053)
Fixes #1997, #2068.

This is tricky because we need to get the return values right (see #1960 for
prior attempts) and we often run into python/mypy#3644. I found that I
could express most signatures correctly using a series of overloads.

A few other changes in here:
- Added splitunc, which according to https://docs.python.org/3/library/os.path.html
  should exist in both Unix and Windows.
- Made the second argument to os.path.curdir Optional to match the implementation.
- Fixed os.path.split, whose previous Path-aware signature triggered python/mypy#3644.
2018-05-15 10:31:40 -04:00
Stanislav Syekirin
4e1cc807aa adding a stub for tkinter.messagebox (#2113) 2018-05-13 08:36:11 -04:00
Phillip Schanely
86f9472bc9 Correct 2 typing comments in inspect module (#2110) 2018-05-12 01:27:29 -04:00
Omar Sandoval
0a30d22f0d Fix Python 3 round() signature (#2107)
In Python 3, the ndigits argument of round() defaults to None. If
ndigits is excluded or explicitly None, the result is always an int. If
ndigits is not None, the result should be the same type as the number.

$ cat test.py
from fractions import Fraction

print(type(round(0.1)))
print(type(round(0.1, None)))
print(type(round(0.1, 0)))

print(type(round(Fraction(1, 10))))
print(type(round(Fraction(1, 10), None)))
print(type(round(Fraction(1, 10), 0)))
$ python3 ./test.py
<class 'int'>
<class 'int'>
<class 'float'>
<class 'int'>
<class 'int'>
<class 'fractions.Fraction'>

Update the signatures to allow for an ndigits of None.
2018-05-11 14:02:09 -04:00
Salvo 'LtWorf' Tomaselli
d289c20260 Add __new__ to tuple stub (#2092)
Closes: #2091

Apply suggestions from https://github.com/python/typeshed/pull/2092
2018-05-09 16:30:58 -07:00