summaryrefslogtreecommitdiffstats
path: root/Lib/typing.py
Commit message (Collapse)AuthorAgeFilesLines
* Lib/typing.py copy edits originating from GH-31061 (GH-31684)Miss Islington (bot)2022-03-051-3/+3
| | | | | (cherry picked from commit 2031149b9a7dfab5f5bad63f417e19f4fc2b9661) Co-authored-by: Matt Bogosian <eb3f73+github+com@yaymail.com>
* bpo-46333: Honor `module` parameter in ForwardRef (GH-30536)Miss Islington (bot)2022-02-171-2/+3
| | | | | | | | | | | | The `module` parameter carries semantic information about the forward ref. Forward refs are different if they refer to different module even if they have the same name. This affects the `__eq__`, `__repr__` and `__hash__` methods. Co-authored-by: Andreas Hangauer <andreas.hangauer@siemens.com> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com> Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> (cherry picked from commit 6e7b813195f9bd6a2a15c1f00ef2c0180f6c751a) Co-authored-by: aha79 <34090357+aha79@users.noreply.github.com>
* bpo-46539: Pass status of special typeforms to forward references (GH-30926)Miss Islington (bot)2022-01-271-3/+3
| | | | | | | | | | | Previously this didn't matter because there weren't any valid code paths that could trigger a type check with a special form, but after the bug fix for `Annotated` wrapping special forms it's now possible to annotate something like `Annotated['ClassVar[int]', (3, 4)]`. This change would also be needed for proposed future changes, such as allowing `ClassVar` and `Final` to nest each other in dataclasses. (cherry picked from commit ced50051bb752a7c1e616f4b0c001f37f0354f32) Co-authored-by: Gregory Beauregard <greg@greg.red>
* bpo-46491: Allow Annotated on outside of Final/ClassVar (GH-30864)Miss Islington (bot)2022-01-251-4/+4
| | | | | | | | We treat Annotated type arg as class-level annotation. This exempts it from checks against Final and ClassVar in order to allow using them in any nesting order. Automerge-Triggered-By: GH:gvanrossum (cherry picked from commit e1abffca45b60729c460e3e2ad50c8c1946cfd4e) Co-authored-by: Gregory Beauregard <greg@greg.red>
* [3.9] bpo-45679: Fix caching of multi-value typing.Literal (GH-29334) (GH-29342)Serhiy Storchaka2021-11-031-6/+5
| | | | | | Literal[True, 2] is no longer equal to Literal[1, 2].. (cherry picked from commit 634984d7dbdd91e0a51a793eed4d870e139ae1e0) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* [3.9] bpo-45166: fixes `get_type_hints` failure on `Final` (GH-28279) (GH-28561)Łukasz Langa2021-09-251-10/+21
| | | | | | | Co-authored-by: Łukasz Langa <lukasz@langa.pl> Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>. (cherry picked from commit 784905dbeff68cf788bbeefe0a675af1af04affc) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
* [3.9] bpo-45121: Fix RecursionError when calling Protocol.__init__ from a ↵Ken Jin2021-09-081-0/+5
| | | | | subclass' __init__ (GH-28206) (GH-28233) Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
* bpo-45081: Fix __init__ method generation when inheriting from Protocol ↵Miss Islington (bot)2021-09-021-12/+24
| | | | | | | | (GH-28121) (GH-28132) Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> (cherry picked from commit 0635e201beaf52373f776ff32702795e38f43ae3) Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
* bpo-44806: Fix __init__ in subclasses of protocols (GH-27545) (GH-27559)Miss Islington (bot)2021-08-021-2/+10
| | | | | | | Non-protocol subclasses of protocol ignore now the __init__ method inherited from protocol base classes. (cherry picked from commit 043cd60abed09edddc7185bcf7d039771acc734d) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* [3.9] bpo-41249: Fix postponed annotations for TypedDict (GH-27017) (GH-27205)Ken Jin2021-07-171-7/+13
| | | | | | | | | This fixes TypedDict to work with get_type_hints and postponed evaluation of annotations across modules. This is done by adding the module name to ForwardRef at the time the object is created and using that to resolve the globals during the evaluation. Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Co-authored-by: Germán Méndez Bravo <german.mb@gmail.com> Co-authored-by: Łukasz Langa <lukasz@langa.pl>
* [3.9] Revert "[3.9] bpo-38908: Fix issue when non runtime_protocol does not ↵Ken Jin2021-05-121-12/+4
| | | | | | | raise TypeError (GH-26067)" (GH-26077) Reverts python/cpython#26075 Automerge-Triggered-By: GH:gvanrossum
* [3.9] bpo-38908: Fix issue when non runtime_protocol does not raise ↵Ken Jin2021-05-121-4/+12
| | | | | | | | | TypeError (GH-26067) (GH-26075) (cherry picked from commit c40486a) Co-authored-by: Yurii Karabas 1998uriyyo@gmail.com Automerge-Triggered-By: GH:gvanrossum
* bpo-38352: Add to typing.__all__ (GH-25821) (#25885)Miss Islington (bot)2021-05-041-0/+7
| | | | | | | | This adds IO, TextIO, BinaryIO, Match, and Pattern. Co-authored-by: Łukasz Langa <lukasz@langa.pl> Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> (cherry picked from commit b11557973476963f7c0fd0041eac175bc0d4c514) Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* bpo-42740: Fix get_args for PEP 585 collections.abc.Callable (GH-23963)Miss Islington (bot)2020-12-281-3/+1
| | | | | | PR 1/2. Needs backport to 3.9. (cherry picked from commit 4140f10a16f06c32fd49f9e21fb2a53abe7357f0) Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
* bpo-42059: Fix required/optional keys for TypedDict(..., total=False) ↵Miss Islington (bot)2020-12-141-2/+2
| | | | | | | (GH-22736) (GH-23747) (cherry picked from commit 67b769f5157c9dad1c7dd6b24e067b9fdab5b35d) Co-authored-by: Alex Grönholm <alex.gronholm@nextday.fi>
* [3.9] bpo-42195: Ensure consistency of Callable's __args__ in ↵kj2020-12-141-12/+19
| | | | | collections.abc and typing (GH-23765) Backport of GH-23060.
* bpo-42345: Fix hash implementation of typing.Literal (GH-23383)Miss Islington (bot)2020-11-191-1/+1
| | | | | | | | | | Fix hash implementation of `typing.Literal`. Update docs regarding `typing.Litaral` caching. Base implementation was done in PR GH-23294. (cherry picked from commit 1b54077ff6f5c1379e097e9f8e8648da9826d6ec) Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
* [3.9] bpo-42345: Fix three issues with typing.Literal parameters (GH-23294) ↵Yurii Karabas2020-11-171-23/+77
| | | | | | | | | | | | | (GH-23335) Literal equality no longer depends on the order of arguments. Fix issue related to `typing.Literal` caching by adding `typed` parameter to `typing._tp_cache` function. Add deduplication of `typing.Literal` arguments. (cherry picked from commit f03d318ca42578e45405717aedd4ac26ea52aaed) Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
* bpo-42233: Correctly repr GenericAlias when used with typing module (GH-23081)Miss Islington (bot)2020-11-071-0/+2
| | | | | | | | | | | | | | | | | | Noticed by @serhiy-storchaka in the bpo. `typing`'s types were not showing the parameterized generic. Eg. previously: ```python >>> typing.Union[dict[str, float], list[int]] 'typing.Union[dict, list]' ``` Now: ```python >>> typing.Union[dict[str, float], list[int]] 'typing.Union[dict[str, float], list[int]]' ``` Automerge-Triggered-By: GH:gvanrossum (cherry picked from commit 1f7dfb277e5b88cddc13e5024766be787a3e9127) Co-authored-by: kj <28750310+Fidget-Spinner@users.noreply.github.com>
* [3.9] Fix typo in typing.py (GH-22121) (GH-22156)Miss Islington (bot)2020-09-081-1/+1
| | | | | | | This is a trivial PR to fix a typo in a docstring in typing.py. From reverences -> references (cherry picked from commit 84ef33c5117acd9867781135a9aeb62052432e8a) Co-authored-by: Graham Bleaney <gbleaney@gmail.com>
* bpo-41341: Recursive evaluation of ForwardRef in get_type_hints (GH-21553)Miss Islington (bot)2020-07-261-6/+14
| | | | | | | | The issue raised by recursive evaluation is infinite recursion with recursive types. In that case, only the first recursive ForwardRef is evaluated. (cherry picked from commit 653f420b53a3aa87316cef59de8d3f5d9e11deb4) Co-authored-by: wyfo <joperez@hotmail.fr>
* bpo-39168: Remove the __new__ method of typing.Generic (GH-21327)Miss Islington (bot)2020-07-051-10/+0
| | | | | | Automerge-Triggered-By: @gvanrossum (cherry picked from commit 7fed75597fac11f9a6c769e2b6c6548fe0e4049d) Co-authored-by: Zackery Spytz <zspytz@gmail.com>
* bpo-40257: Tweak docstrings for special generic aliases. (GH-20022)Serhiy Storchaka2020-05-101-1/+4
| | | | * Add the terminating period. * Omit module name for builtin types.
* bpo-40397: Fix subscription of nested generic alias without parameters. ↵Serhiy Storchaka2020-05-101-2/+4
| | | | (GH-20021)
* bpo-40397: Remove __args__ and __parameters__ from _SpecialGenericAlias ↵Serhiy Storchaka2020-05-101-80/+87
| | | | (GH-19984)
* bpo-40397: Refactor typing._GenericAlias (GH-19719)Serhiy Storchaka2020-05-071-191/+198
| | | | | | Make the design more object-oriented. Split _GenericAlias on two almost independent classes: for special generic aliases like List and for parametrized generic aliases like List[int]. Add specialized subclasses for Callable, Callable[...], Tuple and Union[...].
* bpo-40389: Improve repr of typing.Optional (#19714)Vlad Serebrennikov2020-04-301-0/+7
|
* bpo-40398: Fix typing.get_args() for special generic aliases. (GH-19720)Serhiy Storchaka2020-04-271-1/+3
|
* bpo-40396: Support GenericAlias in the typing functions. (GH-19718)Serhiy Storchaka2020-04-261-5/+18
|
* Fix typo in Lib/typing.py (GH-19717)Nickolena Fisher2020-04-261-1/+1
|
* bpo-40336: Refactor typing._SpecialForm (GH-19620)Serhiy Storchaka2020-04-231-77/+61
|
* bpo-39942:Fix failure in `TypeVar` when missing `__name__` (GH-19616)HongWeipeng2020-04-201-1/+4
| | | https://bugs.python.org/issue39942
* bpo-40257: Improve help for the typing module (GH-19546)Serhiy Storchaka2020-04-181-0/+6
| | | | | | * Show docstring for special forms. * Show docstring for special generic aliases. * Show documentation for __origin__ for generic aliases.
* bpo-40187: Refactor typing.TypedDict. (GH-19372)Serhiy Storchaka2020-04-081-34/+33
|
* bpo-40185: Refactor typing.NamedTuple (GH-19371)Serhiy Storchaka2020-04-081-42/+43
|
* bpo-39481: Implementation for PEP 585 (#18239)Guido van Rossum2020-04-071-3/+4
| | | | | | | | | | | | This implements things like `list[int]`, which returns an object of type `types.GenericAlias`. This object mostly acts as a proxy for `list`, but has attributes `__origin__` and `__args__` that allow recovering the parts (with values `list` and `(int,)`. There is also an approximate notion of type variables; e.g. `list[T]` has a `__parameters__` attribute equal to `(T,)`. Type variables are objects of type `typing.TypeVar`.
* bpo-40182: Remove the _field_types attribute of the NamedTuple class (GH-19368)Serhiy Storchaka2020-04-041-4/+2
|
* bpo-36517: Raise error on multiple inheritance with NamedTuple (GH-19363)Serhiy Storchaka2020-04-041-0/+3
|
* Convert tuples to sets for faster searches (GH-19365)Raymond Hettinger2020-04-041-3/+3
|
* bpo-39572: Document ’total’ flag of TypedDict (GH-18554)ananthan-1232020-02-191-1/+14
|
* bpo-39627: Fix TypedDict totality check for inherited keys (#18503)Vlad Emelianov2020-02-131-13/+20
| | | (Adapted from https://github.com/python/typing/pull/700)
* bpo-39491: Mention Annotated in get_origin() docstring (GH-18379)Jakub Stasiak2020-02-071-2/+2
| | | I forgot to do it in https://github.com/python/cpython/pull/18260.
* bpo-39491: Merge PEP 593 (typing.Annotated) support (#18260)Jakub Stasiak2020-02-051-5/+121
| | | | | | | | | | | | | | | | | | | | | | | | | * bpo-39491: Merge PEP 593 (typing.Annotated) support PEP 593 has been accepted some time ago. I got a green light for merging this from Till, so I went ahead and combined the code contributed to typing_extensions[1] and the documentation from the PEP 593 text[2]. My changes were limited to: * removing code designed for typing_extensions to run on older Python versions * removing some irrelevant parts of the PEP text when copying it over as documentation and otherwise changing few small bits to better serve the purpose * changing the get_type_hints signature to match reality (parameter names) I wasn't entirely sure how to go about crediting the authors but I used my best judgment, let me know if something needs changing in this regard. [1] https://github.com/python/typing/blob/8280de241fd8c8afe727c7860254b753e383b360/typing_extensions/src_py3/typing_extensions.py [2] https://github.com/python/peps/blob/17710b879882454d55f82c2d44596e8e9f8e4bff/pep-0593.rst
* bpo-39493: Fix definition of IO.closed in typing.py (#18265)Shantanu2020-01-301-0/+1
|
* Better runtime TypedDict (GH-17214)Zac Hatfield-Dodds2019-11-241-3/+15
| | | | | This patch enables downstream projects inspecting a TypedDict subclass at runtime to tell which keys are optional. This is essential for generating test data with Hypothesis or validating inputs with typeguard or pydantic.
* bpo-37838: get_type_hints for wrapped functions with forward reference ↵benedwards142019-11-211-1/+5
| | | | | | (GH-17126) https://bugs.python.org/issue37838
* bpo-38407: Add docstrings for typing.SupportsXXX classes. (GH-16644)Serhiy Storchaka2019-10-081-0/+7
|
* bpo-38405: Make nested subclasses of typing.NamedTuple pickleable. (GH-16641)Serhiy Storchaka2019-10-081-1/+1
|
* cleanup ababstractproperty in typing.py (GH-16432)HongWeipeng2019-09-271-8/+15
|
* bpo-38191: Turn warnings into errors in NamedTuple() and TypedDict(). (GH-16238)Serhiy Storchaka2019-09-171-66/+4
|