Commit Graph

1222 Commits

Author SHA1 Message Date
Dylan Jenkinson
6339f88ae4 Updated the stub for builtins to change slice to take Optional[int] rather than just straight int. 2017-01-18 11:30:41 -08:00
Jukka Lehtosalo
97bd6e37b9 Update argparse to accept unicode in many contexts
Change `str` to `Union[str, unicode]` where it seems safe.
I didn't change it in non-covariant contexts since that can
break user code.

I manually verified a subset of the changes by calling the
relevant function with unicode literals (ascii-only).

I'm using `Union[str, unicode]` instead of just `unicode`
so that the stub still works with tools that don't promote
`str` objects to `unicode`.
2017-01-18 08:43:49 -08:00
Roy Williams
aa6a1c53c9 Add stubs for dateutil.tz (#839) 2017-01-17 15:54:15 -08:00
Ethan
3b30996733 Change ast's parse signature to return Module (#836) 2017-01-17 09:49:41 -08:00
Jukka Lehtosalo
35978a7ca5 Make signature of DictMixin.get consistent with Mapping.get (#838) 2017-01-17 14:08:49 +00:00
Jukka Lehtosalo
734ad44a11 Make MRO of UserDict.DictMixin consistent with Mapping (#837)
This fixes MRO conflicts produced by mypy when using multiple
inheritance.
2017-01-17 13:55:31 +00:00
Jelle Zijlstra
511ff30f06 Make functions in asyncio.tasks accept Awaitables (#834) 2017-01-16 16:16:10 -08:00
Guido van Rossum
70d012ed0b Remove trailing commas, pytype doesn't like them 2017-01-13 13:59:07 -08:00
Łukasz Langa
37fc626ffd Add type signature for a WSGI Application to wsgiref (#825)
This type is something core to Python and is useful when typing web applications,
but doesn't actually exist in the stdlib anywhere.  I put this in wsgiref, but I am
open to suggestions as for a better place.

(Original PR by @rowillia.)
2017-01-13 13:36:34 -08:00
Roy Williams
41ba734fc2 Fix return type of next when default parameter is provided.
**test_next.py**:
```python
z = (x*2 for x in range(10))
reveal_type(next(z, None))
```

Before:
```shell
test_next.py:2: error: Revealed type is 'builtins.int*'
```

After:
```shell
test_next.py:2: error: Revealed type is 'Union[builtins.int*, builtins.None]'
```
2017-01-13 09:46:51 -08:00
Russ Allbery
fd4abe5fc3 Add full Python 2 type stubs for OpenSSL.crypto
Also adds the bare minimum of stubs for
cryptography.hazmat.primitives.asymmetric to define the types
referenced here.  (cryptography is a full project in its own right,
with lots of types and internal references.)

This tries to use bytes in places where the module documentation
emphasized that this was opaque bytes and str for arguments and
return values that the module seemd to be treating as regular Python
strings, even though this distinction is not horribly meaningful for
Python 2.
2017-01-13 09:44:37 -08:00
Eric Moyer
2580702036 Match py2 assert*IsInstance with isinstance
The python2 unittest `assertIsInstance` and `assertNotIsInstance` stub
did not allow using a tuple of classes, but that behavior is [in the
documentation][1]. This commit copies the type stub for the isinstance
built-in to the stubs for `assertIsInstance` and `assertNotIsInstance`

I made this commit in response to @gvanrossum's request in
python/typeshed#802 (which fixed this issue for python 3) that I apply
the same fix to python 2.

[1]: https://docs.python.org/2.7/library/unittest.html#unittest.TestCase.assertNotIsInstance
2017-01-12 09:29:23 -08:00
Mohab Usama
cd2d08970d Make calendar.timegm stub accept struct_time 2017-01-11 22:06:39 -08:00
Roy Williams
6008b9dbb1 Overload signature of get to return an Optional value and to allow default to take any type to match runtime behavior.
This chage more closely matches the behavior of `get` at runtime.  Users can pass whatever they want in to the default
parameter and it will be returned if the key is absent.  Additionally, `get` should return an `Optional` if called with
only one parameter.

```python
z = {'a': 22}
reveal_type(z.get('b'))
reveal_type(z.get('b', 22))
reveal_type(z.get('b', 'hello'))
```

Before:
```shell
test_get_default.py:2: error: Revealed type is 'builtins.int*'
test_get_default.py:3: error: Revealed type is 'builtins.int*'
test_get_default.py:4: error: Revealed type is 'builtins.int*'
test_get_default.py:4: error: Argument 2 to "get" of "dict" has incompatible type "str"; expected "int"
```

After:
```shell
test_get_default.py:2: error: Revealed type is 'Union[builtins.int*, builtins.None]'
test_get_default.py:3: error: Revealed type is 'builtins.int'
test_get_default.py:4: error: Revealed type is 'Union[builtins.int, builtins.str*]'
```
2017-01-11 22:02:29 -08:00
Łukasz Langa
05c6c66fa4 Improve CONTRIBUTING.md (#824)
1. Mentioned review requirement for core contributors.
2. Made stub coding style on par with requirements specified on
   the Mypy wiki (we can merge them now).
2017-01-11 17:55:14 -08:00
Łukasz Langa
4603baaa6c Restore stdlib/2/builtins.pyi as a symlink to __builtin__.pyi (#823)
This was broken by python/typeshed@fe0e374.

I confirmed no changes so far were made to builtins.pyi that would require
porting.
2017-01-11 17:24:14 -08:00
Guido van Rossum
b369a3f2db Fix return type of RawConfigParser.items() 2017-01-11 07:09:27 -08:00
Madeleine Thompson
d7edb0365f RawConfigParser.items (#820)
The corresponding line is already present in the Python 2 ConfigParser stubs.
2017-01-10 15:56:26 -08:00
Luiz
d17f7236a1 Add missing imports from collections.abc (#818)
Fixes #817
2017-01-09 17:13:27 -08:00
Ryan C. Thompson
d18484095e atomicwrites: add pyi file (#705)
Authorized by atomicwrites author here:
https://github.com/untitaker/python-atomicwrites/pull/23#issuecomment-260422021
2017-01-09 15:13:48 -08:00
Eric Moyer
62e57618d9 Match assertIsInstance signature with isinstance (#802) 2017-01-09 09:23:46 -08:00
Jelle Zijlstra
f9135c5aa0 add __init_subclass__ to 3.6 (#813)
See also https://github.com/python/mypy/pull/2654
2017-01-09 09:22:20 -08:00
Mohab Usama
534c7c1103 Fix SplitResult and ParseResult stubs (#816) 2017-01-09 08:33:14 -08:00
Madeleine Thompson
4b5e766193 allow_fragments, not allow_framgents (#812) 2017-01-05 14:59:04 -08:00
David Fisher
2cb8e184cc Add NoReturn (#811)
* Add NoReturn
2017-01-04 13:38:05 -08:00
z33ky
93bb4604cb Add special methods for object (#774)
* Add special methods for object

* Add __format__ to 2/__builtin__.pyi too

* Remove redundant __format__ from float.
2017-01-04 13:52:51 +00:00
Cadel Watson
5f98dbb4bf Create stubs for the secrets module in Python 3.6 2017-01-03 18:26:21 -08:00
Jason Fried
61cdd4b7ae AbstractEventLoop missing methods from 3.4.2 and up. (#798)
* Update asyncio/events.pyi for python 3.5.2
create_future, create_task, set_task_factory, get_task_factory
* Gate create_future to >= (3, 5)
2017-01-03 11:05:04 -08:00
Roy Williams
844b32cc64 Fixup types 2017-01-03 10:17:20 -08:00
Roy Williams
7fd08cf073 Add more type information to requests.PreparedRequest 2017-01-03 10:17:20 -08:00
Guido van Rossum
b78eb48b26 Make unittest.removeHandler() an overloaded function.
See https://docs.python.org/3/library/unittest.html#unittest.removeHandler

- Without args it removes the signal handler.
- With a function arg it is a test decorator that temporarily removes
  the handler while the test is running.
2017-01-03 10:15:30 -08:00
lionel-github
f775ef3bc5 Fix RawConfigParser.read stub for Python 2. (#808)
Bring it in line with the stub used in the Python 3 version.
2017-01-02 15:36:03 -08:00
Guido van Rossum
94641f5a84 Revert "Make all single-constraint TypeVars to use bounds" (#806)
Reverts python/typeshed#804.

Reason: until python/mypy#1551 is fixed this gives an error whenever @skip() is used.

Specifically see https://github.com/python/typeshed/pull/804#issuecomment-269926655.
2017-01-01 16:35:50 -08:00
Michael Lee
b46366e77d Make all single-constraint TypeVars to use bounds
According to the documentation in the typing module, TypeVars cannot
have only a single constraint. Attempting to do so will actually result
in an exception at runtime. (However, this error is currently ignored
by mypy -- see https://github.com/python/mypy/pull/2626 for a related
pending pull request).

This commit changes all instances of TypeVars using a single constraint
(e.g. `T = TypeVar('T', Foo)`) to use bounds instead (e.g.
`T = TypeVar('T', bound=Foo)`.

This seems to be the correct fix for plistlib after reading the module
docs, but it's less obvious this is correct for unittest. The unittest
module originally had `_FT = TypeVar('_FT', Callable[[Any], Any])` -- an
alternative fix would have been to do `_FT = Callable[[Any], Any]`.

Although I'm not entirely sure what it means to have a bound be a
Callable, I decided to make the assumption that the original authors
probably meant to use TypeVars instead of type aliases for a reason
(possibly to handle classes implementing `__call__`?)
2017-01-01 11:34:19 -08:00
Roy Williams
c34f11d569 Add more specific types to protobuf 2017-01-01 11:31:03 -08:00
Alex
6a15963e7d Add math.tau to typeshed (#801)
As per https://www.python.org/dev/peps/pep-0628/
2016-12-29 10:17:40 -08:00
Lukasz Langa
bbc7594ec7 Add Flag, IntFlag and auto to enum stubs
Fixes python/mypy#2609
2016-12-28 11:34:56 -08:00
Alex Jurkiewicz
f8717ccfc4 Add support for request.get's 'params' param (#770)
* Add support for request.get's 'params' param

Requests defines the following API:
`get(url, params=None, **kwargs)`

* Improve typing for requests.get(params)

Add support for string form, and tighten restrictions for the dict form
to allow only string keys/vals. Technically, anything is allowed since
the code (I guess) runs `str(key)` and `str(value)`, but it seems better
to keep the stub somewhat strict so it can help pick up potential
errors.
2016-12-28 11:24:03 -08:00
Mateusz Kurek
43f18bc830 Use specific types in dateutil.relativedelta stubs
Improve operator methods for dateutil.relativedelta stubs:
* `__add__` operator method could return other types than `relativedelta` (`datetime.date` or `datetime.datetime`)
* use specific types of operators args instead of Any
* mypy currently does not handle `Union` in op methods (see python/mypy#2129, python/mypy#1442, python/mypy#1264 for details), so I've overloaded it directly
2016-12-28 11:18:03 -08:00
David Euresti
8a8680371a Fix type for six.reraise to make it match sys.exc_info()
The docs for six say the simple case is `reraise(*sys.exc_info())`
2016-12-28 11:15:27 -08:00
gotyaoi
37dff4d8bc Update _curses.pyi
First pass at types for curses functions.
2016-12-28 11:13:57 -08:00
Jason Fried
562ab18792 Update weakref.pyi
ReferenceType __init__ method missing self
2016-12-28 10:24:50 -08:00
Nicolas Duchastel de Montrouge
79c3a40a3a add missing constants (#791)
* add missing constants
* fix spaces for linter and remove duplicate entries
2016-12-24 20:44:57 -08:00
Guido van Rossum
231f00d7da Fix boto stubs.
Replace two `FIXME` comments with `type: ignore`.
See https://github.com/python/mypy/issues/1237.
2016-12-24 09:06:38 -08:00
Łukasz Langa
08432484d5 CONTRIBUTING.md (#790)
Fixes #772.
2016-12-24 08:46:08 -08:00
Alex Jurkiewicz
8e9c53f1db Add basic stub for characteristic (#771)
See https://characteristic.readthedocs.io/en/stable/
2016-12-23 19:11:34 -08:00
Lukasz Langa
7853c26f79 Add missing Dict, List, Set, Tuple imports. 2016-12-22 16:12:04 -08:00
Lukasz Langa
25a46f42be Switch to Python 3.6 for flake8 runs, re-enable E999 checks 2016-12-22 16:02:46 -08:00
Lukasz Langa
937a3ca3fe Remove trailing whitespace 2016-12-22 15:59:29 -08:00
Lukasz Langa
4084296f3f Exclude boto from tests due to broken Liskov Substitution Principle
Starting with python/mypy#2521 mypy is performing stricter function signature
checks.

This makes the stubs diverge from the actual implementation but makes the stubs
internally consistent.  Since this is an actual typing issue in the base
implementation, we need to defer to the original authors to fix it.

Sadly, in this case the breakage is rather fundamental and unlikely to get
fixed by upstream. Consider:

```
  class AWSAuthConnection(object):
    def make_request(self, method, path, headers=None, data='', host=None,
      auth_path=None, sender=None, override_num_retries=None,
      params=None, retry_handler=None): ...

  class AWSQueryConnection(AWSAuthConnection):
    def make_request(self, action, params=None, path='/', verb='GET'): ...
```

Hence, until we have a workaround for the error produced by Mypy, we're
excluding those stubs from being tested against.
2016-12-22 15:54:20 -08:00