Commit Graph

145 Commits

Author SHA1 Message Date
Sebastian Rittau
cdc4de1af4 Derive Reversible from Iterable (#4622)
Closes: #4615
2020-11-01 13:17:41 -08:00
Sebastian Rittau
8aa3346a9c Remove some TODOs from IO classes (#4654)
At this point, it is too late to add methods to these semi-protocols as
it would break lots of existing code. Additionally, we are moving away
from these classes to finer-grained protocols anyway.
2020-11-01 13:11:19 -08:00
Utsav
6f943d43ea Added __class_getitem__ (#4695)
Resolves #4682

Co-authored-by: hauntsaninja <>
2020-10-22 14:05:04 -07:00
Eric Traut
bbd8c96e34 Added some missing types from various stdlib stubs (#4466) 2020-08-29 16:45:36 -07:00
Jelle Zijlstra
5f9fd3d127 upgrade black version (#4486)
Manually removed a number of trailing commas to prevent black from unnecessarily
exploding some collections.
2020-08-26 18:36:01 +02:00
Eric Traut
189bdfb279 Added support for PEP613 (TypeAlias) in typing.pyi (#4472)
Co-authored-by: Eric Traut <erictr@microsoft.com>
2020-08-20 20:45:04 -07:00
Eric Traut
f20c565eb3 Added support in typing.pyi for PEP 612 (ParamSpec and Concatenate) (#4446)
Co-authored-by: Eric Traut <erictr@microsoft.com>
2020-08-17 13:49:58 -07:00
Ian Woloschin
5c049cd136 Add __name__ & __qualname__ to Coroutine (#4404) 2020-08-10 20:44:14 -07:00
Sebastian Rittau
4233008b4a TypeVar(bound) accepts strings for forward references (#4410) 2020-08-07 08:31:31 -07:00
Áron Ricardo Perez-Lopez
a770110497 Mark __next__, __iter__, and close in Generator as concrete (#4385)
Closes #4384
2020-08-04 12:16:35 +02:00
Jelle Zijlstra
5d553c9584 apply black and isort (#4287)
* apply black and isort

* move some type ignores
2020-06-28 13:31:00 -07:00
Shantanu
fe58699ca5 collections/typing: fix various arg names (#4258)
This feels nervous, but if it passes unit tests it's unlikely to break
anything
2020-06-28 12:27:21 -07:00
Milap Sheth
66a9a4b5ce Fix type hint of generator throw method (#4253)
* Fix type hint of generator throw method

* Incorporated changes from #4252
2020-06-21 15:23:28 -07:00
Sebastian Rittau
206bff44ed Remove BinaryIO.write() (#4203)
write() is inherited from IO[bytes], where it's defined as
`def write(self, s: AnyStr) -> int: ...`. If AnyStr is bytes,
this should accept bytes, bytearray, and memoryview, so the
overload is unnecessary.

Closes: #4201
2020-06-08 13:40:41 -07:00
Eric N. Vander Weele
4199352287 Fix typing.ForwardRef.__eq__ stub (#4177)
The return type of `__eq___` should be `bool`.

Otherwise, `mypy --disallow-any-unimported --no-silence-site-packages`
fails because the return type becomes `Union[bool, Any]` due to an
unfollowed import.
2020-06-06 08:04:05 -07:00
Rune Tynan
d863210335 Improve TypeVar stub (#4150) 2020-05-30 20:27:59 -07:00
Ivan Levkivskyi
8c7f489d1b Organize special forms in typing (#3966)
This is an accompanying PR for https://github.com/python/mypy/pull/8779, see https://github.com/python/mypy/pull/8779#issuecomment-624001349

I also noticed that Python 2 and Python 3 versions are a bit out of sync, so I also put them back in sync.
2020-05-05 13:55:31 +01:00
Shantanu
496d758769 typing: minor changes (#3933)
* typing: fix argument names of cast
* typing: use private _Alias class

For py37 and above, this is _GenericAlias, for py36 and below it's
_TypeAlias. I don't think we need to make typing.pyi definitions
correspond more precisely, but we should avoid leaking a
typing.TypeAlias class
2020-04-22 19:38:47 +02:00
Debjyoti Biswas
66c20e6b43 Add stub for typing.ForwardRef (#3876)
* Add stub for class ForwardRef

* Add anotation for localns

* PEP8 and add version info check
2020-03-22 08:51:59 -07:00
Shantanu
4b360ca2c8 TypedDict: fix keys, values, items return value (#3529)
Fixes #3473

Co-authored-by: hauntsaninja <>
2020-03-13 21:03:22 -07:00
Shantanu
87791e4e15 re: various fixes (#3746)
* re: mark positional-only args

* re: fix escape arg name

* re: update whitelist
2020-02-21 11:55:11 +01:00
Jakub Stasiak
17a4371803 Document Annotated and modified get_type_hints (PEP 593) (#3731) 2020-02-06 21:34:21 +01:00
Maarten ter Huurne
703b01dd5e Add __init__ to MappingView and its subclasses (#3528)
While these implementations don't matter for the 'typing' module
itself, these are also imported to serve as the implementations
for the 'collection.abc' module.

Fixes #3029
2019-12-21 14:45:17 -08:00
Ryan Hileman
693678b4c3 add no_type_check_decorator stub for #2884 (#3460) 2019-11-25 19:46:57 -08:00
Sebastian Rittau
87d7dd3d95 Fix annotations with literal values (#3411) 2019-10-28 06:59:28 -07:00
Sebastian Rittau
0501e2b329 Annotations for remaining Python 3.8 additions (#3358)
* Add os.add_dll_directory()
* Add memfd_create() and flags
* Add type annotation to flags
* Add stat_result.st_reparse_tag and flags
* Add ncurses_version
* Add Path.link_to()
* Add Picker.reducer_override()
* Add plistlib.UID
* Add has_dualstack_ipv6() and create_server()
* Add shlex.join()
* Add SSL methods and fields
* Add Python 3.8 statistics functions and classes
* Remove obsolete sys.subversion
* Add sys.unraisablehook
* Add threading.excepthook
* Add get_native_id() and Thread.native_id
* Add Python 3.8 tkinter methods
* Add CLOCK_UPTIME_RAW
* Add SupportsIndex
* Add typing.get_origin() and get_args()
* Add unicodedata.is_normalized
* Add unittest.mock.AsyncMock

Currently this is just an alias for Any like Mock and MagicMock. All of
these classes should probably be sub-classing Any and add their own
methods. See also #3224.

* Add unittest cleanup methods
* Add IsolatedAsyncioTestCase
* Add ElementTree.canonicalize() and C14NWriterTarget
* cProfile.Profile can be used as a context manager
* Add asyncio task name handling
* mmap.flush() now always returns None
* Add posonlyargcount to CodeType
2019-10-14 09:53:48 +02: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
62bbdf856c Add several Python 3.8 annotations (#3347) 2019-10-12 19:36:56 +02:00
Sebastian Rittau
8a7d61741d Python3.8 additions and changes (#3337)
* Add as_integer_ratio() to a few types

* Add dirs_exist_ok to copytree()

* int, float, complex accept __index__ args

Also fix complex.__init__ argument names

* Add __reversed__ to dict et al.

* Python 3.8 date(time) arithmetic fixes

* Add CodeType.replace()
2019-10-10 20:51:27 -07:00
Michael J. Sullivan
455f25a5c7 Use Any instead of object in the view types for __and__ and __sub__ (#3294)
This was discussed in #3181 and the correct explanation was given that
object ought to be preferred here. In practice this caused an obscure
issue with mypy when using this operations on the results of
six.viewkeys(), since it decided that it wanted a mapping *from* object
as a result of inference contexts. Grumble.
2019-10-02 08:03:57 +02:00
Sebastian Rittau
c32e1e2280 Enable --disallow-any-generics for stubs (#3288) 2019-10-01 05:31:34 -07:00
herr kaste
668988fa8c Return concrete sets from ItemsView and KeysView (#3181) 2019-09-05 16:59:59 +02: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
Ivan Levkivskyi
3cfc3150f0 Partially restore old (imprecise) signature of Match.group() (#3190)
This partially reverts #3172
2019-08-16 19:53:52 +01:00
Ville Skyttä
1edd6cd8a8 Add Match.regs (#2819) 2019-08-10 20:21:54 -07:00
Sebastian Rittau
3f6cec9872 Fix Match.group problems (#3172)
* group() may return None values
* group() allows to mix int and str arguments
* Use concrete return type
* Merge overloads
2019-08-08 16:59:20 +02:00
Sebastian Rittau
9ccf9356bf Remove Python 3.4 support (#3147)
Closes #3123
2019-07-27 10:58:21 +02:00
Kamil Bar
4697adcb1a [stdlib][3] Add missing typing.OrderedDict generic stub for Python 3.7.2 (#3153) 2019-07-26 20:46:15 +02:00
Maarten ter Huurne
bdd49d0f3a Fix annotation of re.Match 'lastindex' and 'lastgroup' in Python 3 (#3085)
Both are None if there were no groups matched. Also 'lastgroup'
will be None if the matched group was nameless.

The Python 2 versions of these annotations already used Optional.
2019-06-22 10:18:16 -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
Viktor Roytman
07d4938251 Add missing methods to ItemsView and KeysView, including isdisjoint (#2997) 2019-05-20 02:12:22 +02:00
Mark Mendoza
2cf4af784c Convert typing.ContextManager.exit to use dunder parameter names (#2980) 2019-05-15 13:30:20 -07:00
Jia Chen
ec16e435eb Use dunder parameter name in Container.__contains__ (#2953)
According to Ivan, PEP 544 intentionally did not specify whether method conformance check in protocol inference should look at parameter names. For example, it's up to the type checker to decide whether a class with method defined as `def foo(self, x: int)` would implement a protocol with method `def foo(self, y: int)`.
Mypy decided to ignore parameter names altogether, but we Pyre team decided to be more strict and refuse to match different parameter names (as it is unsound to do so when those methods are invoked with named parameters). Since we rely on the typeshed stubs, we want to make sure at least the important stubs on typeshed conform to our standard. 
This PR changes `Container.__contains__` to use dunder (i.e. positional-only) parameter name specified in PEP484. This change should not affect mypy since it ignores parameter names, but will make Pyre happy as it eliminate the naming requirement for all classes that want to conform to the `Container` protocol.
2019-05-04 22:00:47 -04:00
Michael Lee
efb67946f8 Use variable annotations everywhere (#2909) 2019-04-13 10:40:52 +02:00
秋葉
b3c76aab49 KeysView and ItemsView should accecpt Iterable argument in set operation (#2906) 2019-04-12 23:05:58 -07: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
Joshua Oreman
f8612a77bb Make AsyncGenerator.aclose() properly return Awaitable[None] (#2786)
Fixes #2785. The rationale is discussed there.
2019-02-10 22:35:17 -08:00