Commit Graph

2050 Commits

Author SHA1 Message Date
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
c55cf13d8e make difflib use str on 3 and AnyStr on 2 (#2160) 2018-05-24 13:53:42 -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
Sebastian Rittau
8b84e9cf13 Improve wsgiref stubs (#2145)
* Use typing.Text

* Add InputStream and ErrorStream WSGI protocols

* Fix return type of WSGIApplication

* Add type hints to wsgiref.validate

* Replace _Bytes by plain bytes

* Add wsgiref.util

* Add wsgiref.headers

* ErrorWrapper.writelines() takes an Iterable

* Fix start_response return type
* Make Python 2 and 3 branches resemble each other more closely
* Use typing.NoReturn
* Fix WriteWrapper.writer type

* Change return type of WriteWrapper.writer to Any
2018-05-23 08:19:07 -07:00
Guido van Rossum
a392989a30 Add support for well_known_types to google/protobuf (#2157)
Fixes #2154
2018-05-22 21:57:07 -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
Ilya Konstantinov
128a49a32d Fix LoggerAdapter.process first argument (#2153)
Standard implementation is:
```
def process(self, msg, kwargs):
    kwargs["extra"] = self.extra
    return msg, kwargs
```
so the signature is clearly `(Text, ...) -> (Text, ...)` (or `(str, ...) -> (str, ...)`, but following the other stubs here, I gather it's `Text`).
2018-05-21 08:27:16 -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
Semyon Proshev
6a080cd0db Use assignments instead of redefinitions for aliases in attrs (#2143) 2018-05-17 20:27:34 -07:00
Semyon Proshev
9275be244f Update NamedTuple _make and _replace parameters in Python 2 (#2144) 2018-05-17 11:03:55 -07:00
Dmitry Figol
f7f00c52af socket.create_connection allows host to be None (#2136) 2018-05-17 09:45:59 -04: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
f4d19d9f61 Remove selenium stubs (#2137)
These stubs have not been used by anything for a while
(`remote` doesn't have a __init__.pyi). The quality of the stubs is also
lacking.
2018-05-16 11:50:01 -04:00
Ethan Smith
66545f147a Fix protobuf stubs (#2135) 2018-05-15 20:21:23 -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
Alex Vandiver
5505cb83bb Add generated stubs for google.protobuf, from its protobufs (#2095)
This fleshes out the auto-generated pieces of `google.protobuf`, by
using the go version of https://github.com/dropbox/mypy-protobuf to
generate mypy stubs from the .proto files in
https://github.com/google/protobuf/tree/master/src/google/protobuf

Generated from current `master` of google/protobuf, 25625b956a.

Ref google/protobuf#3803, python/typeshed#1705
2018-05-15 10:11:01 -04:00
Jelle Zijlstra
463b4144dc explicitly import boto.regioninfo (#2121)
This may be causing intermittent test failures (see discussion on gitter).
2018-05-15 10:09:44 -04:00
Katelyn Gigante
51446f35fc Add stub for dateutil.rrule (#1808) 2018-05-15 09:04:57 -04:00
Stanislav Syekirin
4e1cc807aa adding a stub for tkinter.messagebox (#2113) 2018-05-13 08:36:11 -04:00
Daniel Li
56a31be7a7 Add stubs for submodules of six.moves (#2108)
To support "from six.moves.cPickle import loads", we must add a stub for
six.moves.cPickle as if it were a real submodule, even though it isn't
implemented as such. This fixes python/mypy#1550.

We don't apply this approach to six.moves.builtins on Python 2, because
it seems to confuse mypy.

We also add stubs for aliases in six.moves whose underlying modules have
been added to typeshed.

For Python 2:
    - six.moves.SimpleHTTPServer (alias for SimpleHTTPServer)

For Python 3:
    - six.moves.tkinter_dialog (alias for tkinter.dialog)
    - six.moves.tkinter_filedialog (alias for tkinter.filedialog)
    - six.moves.tkinter_commondialog (alias for tkinter.commondialog)
    - six.moves.tkinter_tkfiledialog (alias for tkinter.filedialog)
2018-05-12 12:02:44 -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
Omar Sandoval
aab1b20c80 Add missing namespace argument to rlcompleter.Completer (#2105)
This argument has been around since 2.3, and it's documented in the
rlcompleter docstring (although not on python.org).
2018-05-09 22:12:02 -07: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
Jasper Spaans
2df4a32cf5 Let email.message.MIMEPart inherit from Message (#2103)
Also removes some duplication.
2018-05-09 16:28:14 -07:00
Sebastian Rittau
09008599ce Merge Python 2 and 3 wsgiref (#2106)
* Merge Python 2 and 3 wsgiref

* Move wsigref to 2and3
2018-05-09 16:26:03 -07:00
Dominik Gabi
3f196bde44 Make NamedTuple._replace return instance of the self parameter. (#2102) 2018-05-09 16:24:23 -07:00
Danny Weinberg
9b479fd07e Have Python 2 IntEnum values be ints (#2104)
Currently the Python 2 stub for `IntEnum` just inherits from `Enum` without changing anything, meaning that its `value` has type `Any`. This changes it such that, if you know you have an `IntEnum` you get the more specific `int` type for the `value`. Note that this has already been done for Python 3 `IntEnum` (both in `third_party/3/enum.pyi` and `stdlib/3.4/enum.pyi`).
2018-05-08 19:39:45 -07:00
Guido van Rossum
d854d7e2a0 Revert "Fix signature of generic_visit method (#2100)" (#2101)
This reverts commit 39576c5d41.

I merged too soon -- tests are failing.
2018-05-07 11:21:19 -07:00
Thomas Schaper
39576c5d41 Fix signature of generic_visit method (#2100)
This methods returns something that has the same type as the first argument.
Fixes #2085.
2018-05-07 11:20:20 -07:00
Andrew Svetlov
252d79981b Add a stub for sys.implementation (#2097) 2018-05-06 08:40:56 -07:00
Andrew Svetlov
142c7488a5 Implement a stub for netrc standard module (#2098) 2018-05-06 10:25:40 +01:00
Andrew Gaul
29bf24b8b9 Reparent simplejson from 2 to 2and3 (#2088) 2018-05-04 15:59:26 -07:00
David Euresti
863b9b0886 Add new factory arg to attrib and fields_dict (#2096) 2018-05-04 07:53:52 -07:00
Emil Hessman
4d8010a988 Define threading.local as a proper class (#2086)
Fixes #1591
2018-04-30 08:48:12 -07:00
Emil Hessman
97e261cce8 Define SimpleNamespace as a proper class (#2087) 2018-04-29 23:02:13 -07:00
Jelle Zijlstra
fc9a822348 specify what type Binary is (#2057)
Fixes python/mypy#4916.
2018-04-27 14:40:33 -07:00
Jelle Zijlstra
46f0bb8b91 support unicode in Python 2 for difflib (#2055)
Fixes #1961.

I mostly just replaced all str annotations with Text, including in return types. This is
only broadly correct; diffing a str and a unicode sequence actually results in a mixed
output of str and unicode. We could also keep the return types as str if using Text
causes errors in real code. For callbacks that take str, I introduced a Union alias
because a callable taking a str would not be a compatible with a parameter of type
Callable[[Text], bool].

I also fixed the return type of difflib.restore.
2018-04-27 14:39:18 -07:00
Jelle Zijlstra
f60ffe47a2 add attributes to locale (#2056)
Fixes #1888.
2018-04-27 14:38:22 -07:00
Jelle Zijlstra
c7e3e9890d add UserDict.__init__ for Python 3 (#2083)
Fixes #2075
2018-04-27 14:38:00 -07:00
Jelle Zijlstra
9e25506cab add missing attributes to Python 2 unicode errors (#2084) 2018-04-27 14:37:20 -07:00
Jelle Zijlstra
5554b0b19b argparse.ArgumentParser.error never returns (#2082)
And neither does `.exit`.

Fixes #2081.
2018-04-25 21:30:31 -07:00
Zabolekar
5ddff9c44a Add a stub for tkinter.filedialog and for the modules it imports (#2058) 2018-04-25 19:44:42 -07:00
Martijn Pieters
ecae01a37d collections.OrderedDict dict views are reversible (#2079)
Add the *View subclasses for OrderedDict use, with appropriate __reversed__
hints.

Fixes python/typeshed#2078
2018-04-25 19:44:25 -07:00
David Euresti
664d30c44b Fix attr.Factory signature (#2077)
The first overload was catching all calls including take_self=True.
Fix it by modifying the overloads.

Fixes https://github.com/python-attrs/attrs/issues/366
2018-04-23 12:27:14 -07:00