Commit Graph

42 Commits

Author SHA1 Message Date
Łukasz Hanuszczak
c8c6271365 Make NamedTuple accept Text names (#2762)
Closes #2761
2019-02-09 19:06:07 +01:00
Guido van Rossum
de50614957 Stop inheriting Sized in collection ABCs (#2658)
Instead define abstract __len__ in affected classes.

Fixes #2655 without breaking
https://github.com/rominf/ordered-set-stubs/issues/1
2018-11-30 13:10:35 -08:00
Jukka Lehtosalo
eaeb5fcf13 Revert "Move Sized earlier in the bases of Sequence (#2602)" (#2657)
This reverts commit 4dc21f04dd.

Fixes #2655.
2018-11-30 14:48:55 +00:00
Guido van Rossum
4dc21f04dd Move Sized earlier in the bases of Sequence (#2602)
See https://github.com/rominf/ordered-set-stubs/issues/1:
class OrderedSet(MutableSet[T], Sequence[T]): ...
works in Python 3, but not in Python 2 -- this fixes that
2018-11-13 20:47:48 -08:00
Jelle Zijlstra
bc3f9fe1d3 fix typing.Pattern in Python 2 (#2219)
Fixes #2199
2018-10-01 20:35:13 -07:00
Michael R. Crusoe
2e0af18dda slices of MutableSequences are also MutableSequences (#2428) 2018-09-25 13:06:59 -07:00
Ilya Konstantinov
fe04d3aa2d Accept str in cast (#2408) 2018-08-21 07:53:35 -07:00
Yusuke Miyazaki
6192cce9d9 Avoid using string literals in type annotations (#2294) 2018-07-02 20:23:29 -07: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
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
Semyon Proshev
9275be244f Update NamedTuple _make and _replace parameters in Python 2 (#2144) 2018-05-17 11:03:55 -07:00
shahin
d3a9650fa1 Fix return type of re.match, re.search (#1886) 2018-02-19 09:23:57 -08:00
Ivan Levkivskyi
ec2cb8e44f Convert selected ABCs to Protocols (#1220) 2017-11-19 08:52:16 -08:00
Jelle Zijlstra
83ca997140 Change more defaults to ... (#1729)
* codemod ': Any = None' ': Any = ...'
* codemod ': (Union|Optional)([^=]+)\s+=\s+-?\d+' ': \1\2 = ...'
* codemod ': (Union|Optional)([^=]+)\s*=\s*-?(None|False|True)' ': \1\2 = ...'
* codemod ': (int|float|bool)\s*=\s*-?\d+' ': \1 = ...'
* codemod ': (bool)\s*=\s*(False|True)' ': \1 = ...'
* codemod ': Any\s*=\s*(False|True|None)' ': Any = ...'
2017-11-13 06:56:24 -08:00
Jelle Zijlstra
54dd6ba27c Change numerous default values to ... (#1722)
This is the convention, and some default values (e.g. strings) apparently
break pytype.
2017-11-09 06:28:40 -08:00
Matthew Wright
0b721b7af5 Update type of "throw" method of generators to reflect that it can return a value (#1672) 2017-10-25 16:54:18 -04:00
Michael Lee
6d3024fb19 Add NoReturn type to typing stubs (#1496) 2017-07-20 21:24:34 -07:00
Ivan Levkivskyi
97737ce8c2 Add collections import in typing for type aliases to always work (#1456)
* Add collections import in typing for type aliases to always work

* Add mypy issue number to the comment
2017-07-03 10:01:19 -07:00
mistermocha
5306d6f5a7 Correct implementation of standard types besides "object" (#1340)
Per https://github.com/python/mypy/issues/2989
2017-06-23 09:45:48 -07:00
Semyon Proshev
5db571a8f3 Update typing.MutableMapping.update stubs to allow keyword-only arguments (#1370) 2017-05-30 21:44:10 -07:00
DmitriyS
9f433a57f4 Fix type stubs in typing.pyi (#1263) 2017-05-28 13:13:20 -07:00
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
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
a778704b30 add Counter, Deque, ChainMap (#928) 2017-02-11 10:52:09 -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
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
TrueBrain
cecb64b59f In TextIO, 'errors' is Optional (#665) 2016-11-05 15:02:35 -07:00
Guido van Rossum
cb97bb54c0 Move 2.7 to 2 (#635)
Closes #579.
2016-10-26 16:24:49 -07:00