Commit Graph

54 Commits

Author SHA1 Message Date
Ryan Hileman
693678b4c3 add no_type_check_decorator stub for #2884 (#3460) 2019-11-25 19:46:57 -08:00
Utkarsh Gupta
91b72d49c7 typing.pyi: Remove verbose and rename from NamedTuple (#3352)
Closes #3235
2019-10-12 21:27:50 +02:00
Sebastian Rittau
c32e1e2280 Enable --disallow-any-generics for stubs (#3288) 2019-10-01 05:31:34 -07:00
Michael Lee
b294782183 Make most contextmanager __exit__ signatures return Optional[bool] (#3179)
This pull request is a follow-up to https://github.com/python/mypy/issues/7214.

In short, within that mypy issue, we found it would be helpful to
determine between contextmanagers that can "swallow" exceptions vs ones
that can't. This helps prevent some false positive when using flags that
analyze control flow such as `--warn-unreachable`. To do this,
Jelle proposed assuming that only contextmanagers where the `__exit__`
returns `bool` are assumed to swallow exceptions.

This unfortunately required the following typeshed changes:

1. The typing.IO, threading.Lock, and concurrent.futures.Executor
   were all modified so `__exit__` returns `Optional[None]` instead
   of None -- along with all of their subclasses.

   I believe these three types are meant to be subclassed, so I felt
   picking the more general type was correct.

2. There were also a few concrete types (e.g. see socketserver,
   subprocess, ftplib...) that I modified to return `None` -- I checked
   the source code, and these all seem to return None (and don't appear
   to be meant to be subclassable).

3. contextlib.suppress was changed to return bool. I also double-checked
   the unittest modules and modified a subset of those contextmanagers,
   leaving ones like `_AssertRaisesContext` alone.
2019-08-16 16:13:33 -07:00
Ville Skyttä
1edd6cd8a8 Add Match.regs (#2819) 2019-08-10 20:21:54 -07:00
Ivan Levkivskyi
01c2fa5a14 Sync recent typing and typing_extensions updates (#3070)
This includes two things to sync up with recent runtime updates:
* Move `Final`, `@final`, `Literal`, and `TypedDict` to `typing` (`typing_extensions` still defines or re-exports them)
* Rename `@typing.runtime` to `@typing.runtime_checkable`, while keeping `@runtime` as a backwards-compatible alias in `typing_extensions`.
2019-06-18 02:31:54 +01:00
Mark Mendoza
2cf4af784c Convert typing.ContextManager.exit to use dunder parameter names (#2980) 2019-05-15 13:30:20 -07:00
Michael Lee
efb67946f8 Use variable annotations everywhere (#2909) 2019-04-13 10:40:52 +02:00
Sebastian Rittau
bd10d8aad4 Add @typing.type_check_only (#2679)
Cf. python/typing#597
2019-04-12 15:32:22 -07:00
Michael J. Sullivan
0350e9fa89 Fix some issues with __round__ (#2907)
In python 3, add an overload for there being no digits argument
and make it return int.

In python 2, __round__ doesn't exist and SupportsRound doesn't exist
in the typing module. Use SupportsFloat for python 2 round().

Remove decimal's __round__ overload that takes None, since it doesn't exist
2019-04-09 11:45:10 -07:00
Ivan Levkivskyi
3d638b0677 Revert "Fixing signature for Mapping.get's default parameter (#2810)" (#2817)
This reverts commit 3f83195558.
2019-02-27 18:09:46 +00:00
Mark Mendoza
3f83195558 Fixing signature for Mapping.get's default parameter (#2810) 2019-02-22 21:20:02 -08:00
Ł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