Commit Graph

64 Commits

Author SHA1 Message Date
Jelle Zijlstra
4f2dd0f446 remove unused type ignore flags (#1346)
Verified that none of those are necessary for pytype.
2017-05-26 08:28:51 -07:00
Jelle Zijlstra
7dd2f80194 Fixes to ContextManager (#1249)
* add typing.ContextManager for 3.6+ only

This fixes the easier part of #655.

Would it make sense to add a generic typing.ContextManager that exists in any Python version?

* update comment

* fix argument types for ContextManager.__exit__

* add AsyncContextManager

* add @asynccontextmanager

* typing.ContextManager now always exists

* back out async-related changes

Will submit those in a separate PR later

* fix import order

* AbstractContextManager only exists in 3.6+

* AbstractContextManager -> ContextManager
2017-05-08 16:21:51 -07:00
Semyon Proshev
a2561cc4b2 Update typing.NamedTuple.__init__ to support fields passed through kwargs (#1239)
* Update `typing.NamedTuple.__init__` to support fields passed through kwargs

* `Verbose` and `rename` were returned to `typing.NamedTuple.__init__`
2017-05-04 08:26:15 -07:00
Andrey Vlasovskikh
8b26422b95 Added missing attributes of typing.Generator and typing.AsyncGenerator (#886) 2017-03-29 11:09:24 -07:00
George King
c2cdb1b025 Fix re Pattern.groupindex annotation. (#1106) 2017-03-27 20:45:51 -07:00
David Euresti
4ac642bd49 Separate MutableMapping.pop into 2 overloaded methods (#1045)
This makes calls with the default value not return a Union
2017-03-21 22:30:27 -07:00
Ivan Levkivskyi
ed9f70c738 Replace frozenset with FrozenSet (#1057) 2017-03-21 07:52:34 -07:00
David Euresti
2fdcd2e9e8 Let MutableMapping.pop take a different default type. (#1044)
This is particularly useful for the idiom `d.pop(k, None)` to remove an item if it exists.

Fixes #278
2017-03-20 12:10:38 -07:00
David Euresti
d43f3be914 Unify stdlib/{2,3}/typing.pyi
Also fix signature of IO.seek, IO.truncate, IO.write, and MutableMapping.update
Fixes #1016

Note: I couldn't put typing.pyi in 2and3 because of an import cycle when adding `import sys` to 2/typing.pyi
2017-03-19 09:43:40 -07:00
Jelle Zijlstra
349ff59f33 change empty bodies from "pass" to "..."
CONTRIBUTING.md says to prefer ... Not the most impactful change but fixing
these will allow us to lint for it in the future and get a consistent style.
2017-03-16 09:13:08 -07:00
=^_^=
82f1104e59 Add Collection to typing.pyi (#967)
Fixes #965
2017-03-10 15:52:08 -08:00
Jelle Zijlstra
a778704b30 add Counter, Deque, ChainMap (#928) 2017-02-11 10:52:09 -08:00
5j9
3973f5851a Define __getitem__ for Match objects of Python 3.6 (#925)
In Python 3.6 __getitem__ was added as a new method for match objects.
m[g] is identical to m.group(g).
2017-02-09 15:23:52 -08:00
miedzinski
d486e2a8d5 Add typing.ClassVar (fixes #888) (#889) 2017-01-29 17:15:04 -08:00
Andrey Vlasovskikh
1d1a2e458c Added methods of typing.NamedTuple (#864) 2017-01-26 11:52:59 -08:00
Jukka Lehtosalo
f2579e532f Update signature of dict.get (#852)
Without this change, mypy can't infer proper types for cases like
`d.get(k, [])` where it needs type context to infer the type of
`[]`. We add the value type to the second argument to `get` using
union types, and this provides the context. This doesn't affect
the effective signature of `get`, other than providing the type
context for mypy.

Also removed some related redundant method definitions where we can
just inherit the base class definition. This makes it easier to
keep the method signatures consistent.

Note that this requires a few mypy PRs before mypy will be able to
use this effectively:

* https://github.com/python/mypy/pull/2718
* https://github.com/python/mypy/pull/2715
2017-01-20 07:41:54 -08:00
Jelle Zijlstra
b96bd698ab Fix return values of athrow and aclose. (#845)
I misread the PEP here (https://www.python.org/dev/peps/pep-0525/#asynchronous-generator-object); both of these return the yielded type.
2017-01-19 12:21:51 -08:00
Jelle Zijlstra
df9d11bf71 add AsyncGenerator to typing.pyi, collections/abc.pyi and collections/__init__.pyi (#815)
This parallels https://github.com/python/typing/pull/346
2017-01-18 13:24:28 -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
Lukasz Langa
67e38b6806 Fixing flake8 E231 errors 2016-12-19 23:53:19 -08:00
Lukasz Langa
fe0e3744cc Fixing flake8 E261 errors 2016-12-19 22:09:35 -08:00
Lukasz Langa
b84f20a011 Fixing flake8 W errors 2016-12-19 21:52:56 -08:00
Guido van Rossum
b46280ec78 Make FrozenSet covariant. (#769)
Follow-up for PR #726.
2016-12-13 11:40:18 -08:00
Calen Pennington
5ba7abc559 Add GenericMeta (so that classes can be Generic when they already hav… (#703) 2016-12-02 12:09:59 -08:00
Guido van Rossum
ec4987fa5d Fix AwaitableGenerator inheritance; Awaitable is the return value, not the yielded value (#679) 2016-11-10 11:57:31 -08:00
TrueBrain
cecb64b59f In TextIO, 'errors' is Optional (#665) 2016-11-05 15:02:35 -07:00
Guido van Rossum
53014497c4 Add Coroutine. Fix signature for Generator.throw(). (#656) 2016-11-04 11:46:50 -07:00
Elazar
7224b67532 Remove @builtinclass (#626) 2016-10-22 12:25:02 -07:00
Elazar
1d820d48cf Add signatures for cast() and NewType (#549)
(Mypy ignores these in favor of hard-coded behaviors, but the signatures here may be useful for other tools.)
2016-09-14 14:55:06 -07:00
Elazar
e25b882041 Full signature for namedtuple (#541) 2016-09-13 16:17:26 -07:00
Guido van Rossum
8b0e6b886d Fix signature for __exit__ (#542) 2016-09-13 11:00:01 -07:00
Guido van Rossum
25cb6e4ab4 Make Mapping covariant. (#512)
* Make Mapping covariant.

Fixes #510.

This requires a `# type: ignore` on `__getitem__` and `get` because
mypy complains about covariant parameters.

FWIW typing.py needs to be changed too.  (It was covariant in the
value but invariant in the key -- typeshed was invariant in both.)

* Delete outdated comment.

* Backpeddle a bit -- Mapping key type should not be covariant.
2016-09-05 20:57:37 +01:00
Michael Lee
97bc450acd Make typing.IO inherit Iterator, not Iterable (#502)
In Python, it's possible to use the `next` builtin method on file
objects produced by `open`. This change modifies `typing.IO` so this
usage will successfully typecheck.
2016-08-27 23:31:16 -07:00
Tomasz Elendt
34175b888d Fix __setitem__(slice, ...) of various mutable sequences (#496)
Adds support of assigning iterables to slice of mutable sequences and
bytes to bytearray's slice.
2016-08-23 19:02:50 -07:00
Tomasz Elendt
9451fa922c Add start and stop arguments to Sequence.index in Py >= 3.5 (#489)
Fixes #486.
2016-08-22 14:53:48 -07:00
Nicholas Bishop
a20d5c481a Add type stub for typing.get_type_hints (#480)
Fixes issue #477
2016-08-16 20:41:01 -07:00
Emanuel Barry
0989cb1cb3 Add FrozenSet to the typing stub files (#474) 2016-08-13 19:34:38 -07:00
Guido van Rossum
de4e87f574 Changes required by mypy async-await support (#435) 2016-08-03 17:01:35 -07:00
Jakub Stasiak
44b367c7fe Add re fullmatch() information (#381) 2016-07-26 07:43:29 -07:00
Michael Lee
9ecc1f2147 Add stubs for NewType helper function (#398)
(Note that this is not enough to support NewType(). However it's a prerequisite for the mypy implementation.)
2016-07-26 07:35:28 -07:00
Michael Lee
368c703078 Add dict views to python 2 (#376) 2016-07-21 11:28:35 -07:00
Guido van Rossum
89dfe15008 Add TYPE_CHECKING = True 2016-06-10 17:27:12 -07:00
Scott G. Ainsworth
82b9baed3b Changed all regular expression findall() to return list[Any]. Findall() can return both list[AnyStr] and list[Tuple[AnyStr, AnyStr]]. (#269) 2016-06-05 17:50:12 -07:00
Guido van Rossum
25a45d6daf Revert "WIP: Mapping.{get,pop} can return default type (#223)"
This reverts commit d43adbe97e.

Here's a simple example of code that breaks with this PR:

from typing import Mapping, Dict, Tuple
a = {('0', '0'): 42}  # type: Mapping[Tuple[str, str], int]
b = a.get(('1', '1'), 0)

This gives an error on the last line:
error: No overload variant of "get" of "dict" matches argument types [Tuple[builtins.str, builtins.str], builtins.int]
2016-05-30 11:55:30 -07:00
Valérian Rousset
d43adbe97e WIP: Mapping.{get,pop} can return default type (#223)
* Mapping.{get,pop} can return default type

* Mapping values are covariant
2016-05-30 10:05:44 -07:00
Guido van Rossum
b6b8554c6b Add stub version of Type[C] (#216) 2016-05-24 16:44:13 -07:00
detlefla
e2ce50b525 enable string arguments for start, end, and span methods of Match object 2016-05-07 09:53:24 -07:00
rwbarton
2b80cdf75e Use overloading rather than Union for MutableMapping.update (#174)
See https://github.com/python/mypy/issues/1430 for motivation.
2016-05-01 17:50:01 +01:00
Guido van Rossum
78e6e9b740 Add Text to typing.pyi; it's an alias for unicode in 2.7, for str in 3. 2016-04-16 13:42:17 -07:00
Guido van Rossum
23ec1ff96a Break cycle between typing and collections. (Requires a fix in mypy.) 2016-04-15 21:31:49 -07:00