summaryrefslogtreecommitdiffstats
path: root/Lib/typing.py
Commit message (Collapse)AuthorAgeFilesLines
* [3.10] gh-94245: Fix pickling and copying of typing.Tuple[()] (GH-94260)Serhiy Storchaka2022-06-251-1/+2
|
* [3.10] bpo-46581: Propagate private vars via _GenericAlias.copy_with ↵Matt Bogosian2022-03-111-7/+6
| | | | | | | | | | | | | | | | | (GH-31061) (GH-31821) (Cherry-picked from 32bf3597922ac3f613989582afa2bff43bea8a2f.) GH-26091 added the _typevar_types and _paramspec_tvars instance variables to _GenericAlias. However, they were not propagated consistently. This commit addresses the most prominent deficiency identified in bpo-46581 (namely their absence from _GenericAlias.copy_with), but there could be others. Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* 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-46643: Fix stringized P.args/P.kwargs with get_type_hints (GH-31238)Miss Islington (bot)2022-03-031-1/+2
| | | | | (cherry picked from commit 75d2d945b4e28ca34506b2d4902367b61a8dff82) Co-authored-by: Gregory Beauregard <greg@greg.red>
* [3.10] bpo-46333: Honor `module` parameter in ForwardRef (GH-30536) (GH-31379)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> Automerge-Triggered-By: GH:JelleZijlstra
* [3.10] bpo-46676: Make ParamSpec args and kwargs equal to themselves ↵Gregory Beauregard2022-02-081-0/+10
| | | | | | | (GH-31203) (GH-31210) (cherry picked from commit c8b62bbe46e20d4b6dd556f2fa85960d1269aa45) Co-authored-by: Gregory Beauregard <greg@greg.red>
* [3.10] bpo-46655: allow stringized TypeAlias with get_type_hints (GH-31156). ↵Gregory Beauregard2022-02-071-1/+1
| | | | | | | (#31175) (cherry picked from commit 77b025be4a4cd5a3bfc1b1af560cc57e8e956c98) Co-authored-by: Gregory Beauregard <greg@greg.red>
* bpo-46560: Fix a typo in `typing.ParamSpec's` doc string (GH-30995)Miss Islington (bot)2022-01-281-1/+1
| | | | | (cherry picked from commit ffa505b580464d9d90c29e69bd4db8c52275280a) Co-authored-by: Zackery Spytz <zspytz@gmail.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-44791: Fix substitution of ParamSpec in Concatenate with different ↵Miss Islington (bot)2022-01-271-1/+11
| | | | | | | | | | | parameter expressions (GH-27518) * Substitution with a list of types returns now a tuple of types. * Substitution with Concatenate returns now a Concatenate with concatenated lists of arguments. * Substitution with Ellipsis is not supported. (cherry picked from commit ecfacc362dd7fef7715dcd94f2e2ca6c622ef115) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* 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>
* bpo-45755: [typing] Reveal class attributes of generic in generic aliases in ↵Miss Islington (bot)2021-12-171-0/+3
| | | | | | | `dir()` (GH-29962) (cherry picked from commit d6e13747161d7b634b47d2d3d212ed3be4a21fab) Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
* bpo-44353: Correct docstring for `NewType` (GH-29785)Miss Islington (bot)2021-11-261-1/+1
| | | | | | The docstring for `typing.NewType` is no longer strictly accurate, now that `NewType` is a class, rather than a function (cherry picked from commit 93c65df83cef71a4bc77d71afecdec8744c4f73a) Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* bpo-45679: Fix caching of multi-value typing.Literal (GH-29334)Miss Islington (bot)2021-10-311-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.10] Remove trailing spaces (GH-28709)Serhiy Storchaka2021-10-031-1/+1
|
* bpo-45166: fixes `get_type_hints` failure on `Final` (GH-28279) (GH-28560)Miss Islington (bot)2021-09-251-9/+20
| | | | | | | 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>
* bpo-45121: Fix RecursionError when calling Protocol.__init__ from a ↵Miss Islington (bot)2021-09-081-0/+5
| | | | | | | subclass' __init__ (GH-28206) (GH-28232) (cherry picked from commit c11956a8bddd75f02ccc7b4da7e4d8123e1f3c5f) Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
* bpo-45081: Fix __init__ method generation when inheriting from Protocol ↵Miss Islington (bot)2021-09-031-12/+24
| | | | | | | | (GH-28121) 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-44524: Fix cryptic TypeError message when trying to subclass special ↵Miss Islington (bot)2021-08-281-0/+3
| | | | | | | | forms in `typing` (GH-27710) This was a Python 3.9 regression. (cherry picked from commit a3a4d20d6798aa2975428d51f3a4f890248810cb) Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
* bpo-44524: Don't modify MRO when inheriting from typing.Annotated (GH-27841)Miss Islington (bot)2021-08-251-1/+6
| | | | | (cherry picked from commit 23384a1749359f0ae7aaae052073d44b59e715a1) Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
* bpo-44524: Do not set _name of _SpecialForm without need (GH-27861) (GH-27871)Miss Islington (bot)2021-08-211-11/+8
| | | | | | | | | Because setting non-empty _name affects behavior of other code. In most cases __name__ can be derived from __origin__.__name__. (cherry picked from commit 4ceec495598e78f0776dd46d511dcc612a434dc3) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* bpo-44524: Fix an issue wherein `_GenericAlias._name` was not properly set ↵Miss Islington (bot)2021-08-061-7/+16
| | | | | | | | | for specialforms (GH-27614) Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Co-authored-by: Łukasz Langa <lukasz@langa.pl> (cherry picked from commit 8bdf12e99a3dc7ada5f85bba79c2a9eb9931f5b0) Co-authored-by: Bas van Beek <43369155+BvB93@users.noreply.github.com>
* bpo-44801: Check arguments in substitution of ParamSpec in Callable (GH-27585)Miss Islington (bot)2021-08-041-8/+18
| | | | | (cherry picked from commit 3875a6954741065b136650db67ac533bc70a3eac) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* bpo-44806: Fix __init__ in subclasses of protocols (GH-27545)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>
* bpo-44793: Fix checking the number of arguments when subscribe a generic ↵Miss Islington (bot)2021-08-021-6/+9
| | | | | | | | | | | type with ParamSpec parameter. (GH-27515) For example Callable[P, T][[int], str, float] will now raise an error. Use also term "arguments" instead of "parameters" in error message for too few/many arguments. (cherry picked from commit f92b9133ef67e77605cbd315b6b6c81036ce110e) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* bpo-44761: Change default value of NewType __module__ attr (GH-27406) (GH-27477)Miss Islington (bot)2021-07-301-4/+6
| | | | | (cherry picked from commit 7b975f81e4dba70a42c6279539a7fcfe4211b4c0) Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
* bpo-44732: Rename types.Union to types.UnionType (GH-27342)Miss Islington (bot)2021-07-261-11/+11
| | | | | | | Co-authored-by: Łukasz Langa <lukasz@langa.pl> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> (cherry picked from commit 2b8ad9e6c5f0a66e9ca2d15f85336d8a3eefefb0) Co-authored-by: Hasan <hasan.aleeyev@gmail.com>
* bpo-44676: Serialize the union type using only public API (GH-27323) (GH-27340)Miss Islington (bot)2021-07-241-2/+2
| | | | | | | Remove also the _from_args() constructor. (cherry picked from commit 435a0334d341e5f8faed594d9f015746bb7845db) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* bpo-44731: Simplify the union type implementation (GH-27318) (GH-27334)Ken Jin2021-07-241-0/+6
| | | | | Remove direct support of typing types in the C code because they are already supported by defining methods __or__ and __ror__ in the Python code. Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* [3.10] bpo-44676: Add ability to serialize types.Union (GH-27244) (GH-27333)Pablo Galindo Salgado2021-07-241-2/+2
| | | | | (cherry picked from commit fe13f0b0f696464dd6f283576668dbf57cb11399) Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
* [3.10] bpo-44353: Expand NewType tests for complex __qualname__ (GH-27311) ↵Łukasz Langa2021-07-241-1/+6
| | | | | | | | (GH-27326) Make NewType pickleable by name. (cherry picked from commit e89ef0ad2a299770a88ece8f7a316f7d3eb65c9f) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* bpo-44353: Refactor typing.NewType into callable class (GH-27250) (#27258)Miss Islington (bot)2021-07-201-5/+22
| | | | | (cherry picked from commit 965dd76e9060e27e2253ba8c8d21a142b178720d) Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
* bpo-44524: Add missed __name__ and __qualname__ to typing module objects ↵Miss Islington (bot)2021-07-191-0/+9
| | | | | | | | (GH-27237) (#27246) Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> (cherry picked from commit bce1418541a64a793960182772f985f64afbfa1a) Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
* bpo-44490: Improve typing module compatibility with types.Union (GH-27048) ↵Ken Jin2021-07-191-5/+13
| | | | | | | (#27222) (cherry picked from commit bf89ff96e6ba21bb52b8597b5e51e8ffc57e6589) Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
* [3.10] bpo-44654: Refactor and clean up the union type implementation ↵Miss Islington (bot)2021-07-171-1/+1
| | | | | | (GH-27196) (GH-27219) (cherry picked from commit 0fd27375cabd12e68a2f12cfeca11a2d5043429e)
* bpo-41249: Fix postponed annotations for TypedDict (GH-27017) (#27204)Miss Islington (bot)2021-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> (cherry picked from commit 889036f7ef7290ef15b6c3373023f6a35387af0c) Co-authored-by: Germán Méndez Bravo <german.mb@gmail.com>
* [3.10] bpo-44652: Preserve natural order of args in the union type. ↵Serhiy Storchaka2021-07-161-4/+4
| | | | | | | (GH-27185) (GH-27190) (cherry picked from commit 0cd2d51aadcd2a0c0739a5df0a6235d64f35619e) Automerge-Triggered-By: GH:ambv
* [3.10] bpo-44468: Never skip base classes in `typing.get_type_hints()`, even ↵Miss Islington (bot)2021-06-261-4/+1
| | | | | | | | | | with invalid `.__module__`. (GH-26862) (GH-26920) (cherry picked from commit 7569c0fe91dfcf562dee8c29798ecda74d738aa8) Co-authored-by: will-ca <willchencontact@gmail.com> Automerge-Triggered-By: GH:gvanrossum
* bpo-44098: Drop ParamSpec from most ``__parameters__`` in typing generics ↵Miss Islington (bot)2021-05-131-14/+29
| | | | | | | | | | | (GH-26013) (#26091) Added two new attributes to ``_GenericAlias``: * ``_typevar_types``, a single type or tuple of types indicating what types are treated as a ``TypeVar``. Used for ``isinstance`` checks. * ``_paramspec_tvars ``, a boolean flag which guards special behavior for dealing with ``ParamSpec``. Setting it to ``True`` means this class deals with ``ParamSpec``. Automerge-Triggered-By: GH:gvanrossum (cherry picked from commit b2f3f8e3d81b0bb0ba18f563d82c28ba133c0790)
* bpo-38908: Fix issue when non runtime_protocol failed to raise TypeError ↵Miss Islington (bot)2021-05-121-2/+10
| | | | | | | (GH-26067) (cherry picked from commit c40486a32d7e37b01ead94e701d69847f5b60e30) Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
* bpo-38352: Add to typing.__all__ (GH-25821) (#25884)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-43901: Lazy-create an empty annotations dict in all unannotated user ↵larryhastings2021-04-301-0/+2
| | | | | classes and modules (#25623) Change class and module objects to lazy-create empty annotations dicts on demand. The annotations dicts are stored in the object's `__dict__` for backwards compatibility.
* bpo-43766: Implement PEP 647 (User-Defined Type Guards) in typing.py (#25282)Ken Jin2021-04-271-0/+49
|
* bpo-42904: Change search order of typing.get_type_hints eval (#25632)Ken Jin2021-04-261-1/+10
| | | While surprising (searching globals before locals in one specific case), this is needed for backwards compatibility.
* bpo-38605: Revert making 'from __future__ import annotations' the default ↵Pablo Galindo2021-04-211-7/+0
| | | | | | (GH-25490) This reverts commits 044a1048ca93d466965afc027b91a5a9eb9ce23c and 1be456ae9d53bb1cba2b24fc86175c282d1c2169, adapting the code to changes that happened after it.
* bpo-40443: Remove unused imports (GH-25429)Victor Stinner2021-04-161-1/+0
| | | | | | * pyclbr no longer uses copy * typing no longer uses ast Issue discovered by pyflakes.
* bpo-41515: Fix KeyError raised in get_type_hints (GH-25352)Karthikeyan Singaravelan2021-04-121-1/+4
| | | | | Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Co-authored-by: efahl <36704995+efahl@users.noreply.github.com>
* bpo-42904: Fix get_type_hints for class local namespaces (GH-24201)Ken Jin2021-04-121-1/+2
|
* bpo-43772: Fix TypeVar.__ror__ (GH-25339)Jelle Zijlstra2021-04-111-2/+2
|
* bpo-43783: Add ParamSpecArgs/Kwargs (GH-25298)Jelle Zijlstra2021-04-111-3/+50
|