Commit Graph

177 Commits

Author SHA1 Message Date
Miss Islington (bot) 58967d1abe
Correct typo in typing.py (GH-100423)
In the docstring of `ParamSpec`, the name of `P = ParamSpec('P')` was
mistakenly written as `'T'`.
(cherry picked from commit 68981578ec)

Co-authored-by: david-why <david_why@outlook.com>
2022-12-22 03:43:55 -08:00
Serhiy Storchaka 75dda3b12d
[3.10] gh-94245: Fix pickling and copying of typing.Tuple[()] (GH-94260) 2022-06-25 18:45:46 +03:00
Matt Bogosian 3bc8019606
[3.10] bpo-46581: Propagate private vars via _GenericAlias.copy_with (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>
2022-03-11 16:57:52 +02:00
Miss Islington (bot) 4716f70c85
Lib/typing.py copy edits originating from GH-31061 (GH-31684)
(cherry picked from commit 2031149b9a)

Co-authored-by: Matt Bogosian <eb3f73+github+com@yaymail.com>
2022-03-04 19:17:32 -08:00
Miss Islington (bot) 257f5be7f7
bpo-46643: Fix stringized P.args/P.kwargs with get_type_hints (GH-31238)
(cherry picked from commit 75d2d945b4)

Co-authored-by: Gregory Beauregard <greg@greg.red>
2022-03-02 18:26:50 -08:00
Miss Islington (bot) a17d59a6df
[3.10] bpo-46333: Honor `module` parameter in ForwardRef (GH-30536) (GH-31379)
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 6e7b813195)


Co-authored-by: aha79 <34090357+aha79@users.noreply.github.com>

Automerge-Triggered-By: GH:JelleZijlstra
2022-02-16 19:53:03 -08:00
Gregory Beauregard cbdcae5ab9
[3.10] bpo-46676: Make ParamSpec args and kwargs equal to themselves (GH-31203) (GH-31210)
(cherry picked from commit c8b62bbe46)

Co-authored-by: Gregory Beauregard <greg@greg.red>
2022-02-08 10:41:13 +02:00
Gregory Beauregard e2eeffefed
[3.10] bpo-46655: allow stringized TypeAlias with get_type_hints (GH-31156). (#31175)
(cherry picked from commit 77b025be4a)

Co-authored-by: Gregory Beauregard <greg@greg.red>
2022-02-07 08:21:56 -08:00
Miss Islington (bot) 315a60acd1
bpo-46560: Fix a typo in `typing.ParamSpec's` doc string (GH-30995)
(cherry picked from commit ffa505b580)

Co-authored-by: Zackery Spytz <zspytz@gmail.com>
2022-01-28 10:36:16 -08:00
Miss Islington (bot) bfcb41420a
bpo-46539: Pass status of special typeforms to forward references (GH-30926)
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 ced50051bb)

Co-authored-by: Gregory Beauregard <greg@greg.red>
2022-01-27 08:48:08 -08:00
Miss Islington (bot) 89db090295
bpo-44791: Fix substitution of ParamSpec in Concatenate with different 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 ecfacc362d)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2022-01-27 05:01:24 -08:00
Miss Islington (bot) 41e0aead3d
bpo-46491: Allow Annotated on outside of Final/ClassVar (GH-30864)
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 e1abffca45)

Co-authored-by: Gregory Beauregard <greg@greg.red>
2022-01-25 06:38:45 -08:00
Miss Islington (bot) 87539cc716
bpo-45755: [typing] Reveal class attributes of generic in generic aliases in `dir()` (GH-29962)
(cherry picked from commit d6e1374716)

Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
2021-12-17 03:33:07 -08:00
Miss Islington (bot) 3f024e27c2
bpo-44353: Correct docstring for `NewType` (GH-29785)
The docstring for `typing.NewType` is no longer strictly accurate, now that `NewType` is a class, rather than a function
(cherry picked from commit 93c65df83c)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2021-11-26 06:58:13 -08:00
Miss Islington (bot) 3997f3ce8a
bpo-45679: Fix caching of multi-value typing.Literal (GH-29334)
Literal[True, 2] is no longer equal to Literal[1, 2].
(cherry picked from commit 634984d7db)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2021-10-31 01:43:40 -07:00
Serhiy Storchaka 93242d7a2a
[3.10] Remove trailing spaces (GH-28709) 2021-10-03 20:03:49 +03:00
Miss Islington (bot) d312b8516e
bpo-45166: fixes `get_type_hints` failure on `Final` (GH-28279) (GH-28560)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
(cherry picked from commit 784905dbef)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2021-09-25 11:21:13 +02:00
Miss Islington (bot) c081649e6d
bpo-45121: Fix RecursionError when calling Protocol.__init__ from a subclass' __init__ (GH-28206) (GH-28232)
(cherry picked from commit c11956a8bd)

Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
2021-09-08 17:05:23 +02:00
Miss Islington (bot) 79e9f5a584
bpo-45081: Fix __init__ method generation when inheriting from Protocol (GH-28121)
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
(cherry picked from commit 0635e201be)

Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
2021-09-02 23:26:53 -07:00
Miss Islington (bot) 81fa08c5ea
bpo-44524: Fix cryptic TypeError message when trying to subclass special forms in `typing` (GH-27710)
This was a Python 3.9 regression.
(cherry picked from commit a3a4d20d67)

Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
2021-08-28 11:09:45 -07:00
Miss Islington (bot) 06e9a35169
bpo-44524: Don't modify MRO when inheriting from typing.Annotated (GH-27841)
(cherry picked from commit 23384a1749)

Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
2021-08-25 11:36:47 -07:00
Miss Islington (bot) 5bd27c3be5
bpo-44524: Do not set _name of _SpecialForm without need (GH-27861) (GH-27871)
Because setting non-empty _name affects behavior of other code.

In most cases __name__ can be derived from __origin__.__name__.
(cherry picked from commit 4ceec49559)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2021-08-21 12:33:14 +03:00
Miss Islington (bot) 36a2497093
bpo-44524: Fix an issue wherein `_GenericAlias._name` was not properly set 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 8bdf12e99a)

Co-authored-by: Bas van Beek <43369155+BvB93@users.noreply.github.com>
2021-08-06 10:08:27 -07:00
Miss Islington (bot) 536e35ae6a
bpo-44801: Check arguments in substitution of ParamSpec in Callable (GH-27585)
(cherry picked from commit 3875a69547)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2021-08-04 13:36:01 -07:00
Miss Islington (bot) 2cc19a5463
bpo-44806: Fix __init__ in subclasses of protocols (GH-27545)
Non-protocol subclasses of protocol ignore now the __init__ method
inherited from protocol base classes.
(cherry picked from commit 043cd60abe)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2021-08-02 10:08:59 -07:00
Miss Islington (bot) c8db292012
bpo-44793: Fix checking the number of arguments when subscribe a generic 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 f92b9133ef)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2021-08-02 00:08:24 -07:00
Miss Islington (bot) 56122b0bba
bpo-44761: Change default value of NewType __module__ attr (GH-27406) (GH-27477)
(cherry picked from commit 7b975f81e4)

Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
2021-07-30 15:48:01 +02:00
Miss Islington (bot) 8a37e8cf45
bpo-44732: Rename types.Union to types.UnionType (GH-27342)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
(cherry picked from commit 2b8ad9e6c5)

Co-authored-by: Hasan <hasan.aleeyev@gmail.com>
2021-07-26 12:02:58 -07:00
Miss Islington (bot) 0aea99e444
bpo-44676: Serialize the union type using only public API (GH-27323) (GH-27340)
Remove also the _from_args() constructor.
(cherry picked from commit 435a0334d3)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2021-07-24 22:35:33 +03:00
Ken Jin ca5a4cf826
bpo-44731: Simplify the union type implementation (GH-27318) (GH-27334)
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>
2021-07-24 15:49:25 +01:00
Pablo Galindo Salgado 9356d1e47d
[3.10] bpo-44676: Add ability to serialize types.Union (GH-27244) (GH-27333)
(cherry picked from commit fe13f0b0f6)

Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
2021-07-24 15:08:53 +01:00
Łukasz Langa 05f5d8e48c
[3.10] bpo-44353: Expand NewType tests for complex __qualname__ (GH-27311) (GH-27326)
Make NewType pickleable by name.
(cherry picked from commit e89ef0ad2a)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2021-07-24 12:07:56 +02:00
Miss Islington (bot) c2f33dfc83
bpo-44353: Refactor typing.NewType into callable class (GH-27250) (#27258)
(cherry picked from commit 965dd76e90)

Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
2021-07-20 17:24:57 +02:00
Miss Islington (bot) c895f2bc4f
bpo-44524: Add missed __name__ and __qualname__ to typing module objects (GH-27237) (#27246)
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
(cherry picked from commit bce1418541)

Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
2021-07-19 19:57:27 +02:00
Ken Jin a272164959
bpo-44490: Improve typing module compatibility with types.Union (GH-27048) (#27222)
(cherry picked from commit bf89ff96e6)

Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
2021-07-19 07:22:59 -07:00
Miss Islington (bot) 03aad3049d
[3.10] bpo-44654: Refactor and clean up the union type implementation (GH-27196) (GH-27219)
(cherry picked from commit 0fd27375ca)
2021-07-18 00:10:21 +03:00
Miss Islington (bot) 480f29f913
bpo-41249: Fix postponed annotations for TypedDict (GH-27017) (#27204)
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 889036f7ef)

Co-authored-by: Germán Méndez Bravo <german.mb@gmail.com>
2021-07-17 10:48:17 +02:00
Serhiy Storchaka 80844d1ebc
[3.10] bpo-44652: Preserve natural order of args in the union type. (GH-27185) (GH-27190)
(cherry picked from commit 0cd2d51aad)

Automerge-Triggered-By: GH:ambv
2021-07-16 06:42:04 -07:00
Miss Islington (bot) 3df23b5199
[3.10] bpo-44468: Never skip base classes in `typing.get_type_hints()`, even with invalid `.__module__`. (GH-26862) (GH-26920)
(cherry picked from commit 7569c0fe91)


Co-authored-by: will-ca <willchencontact@gmail.com>

Automerge-Triggered-By: GH:gvanrossum
2021-06-26 16:52:28 -07:00
Miss Islington (bot) c55ff1b352
bpo-44098: Drop ParamSpec from most ``__parameters__`` in typing generics (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 b2f3f8e3d8)
2021-05-13 10:19:24 -07:00
Miss Islington (bot) a2d94a0a9b
bpo-38908: Fix issue when non runtime_protocol failed to raise TypeError (GH-26067)
(cherry picked from commit c40486a32d)

Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
2021-05-12 09:09:04 -07:00
Miss Islington (bot) e1bcc88a50
bpo-38352: Add to typing.__all__ (GH-25821) (#25884)
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 b115579734)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2021-05-04 11:51:33 +02:00
larryhastings 2f2b69855d
bpo-43901: Lazy-create an empty annotations dict in all unannotated user 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.
2021-04-29 20:09:08 -07:00
Ken Jin 05ab4b60ab
bpo-43766: Implement PEP 647 (User-Defined Type Guards) in typing.py (#25282) 2021-04-27 07:31:04 -07:00
Ken Jin 1b1f9852bd
bpo-42904: Change search order of typing.get_type_hints eval (#25632)
While surprising (searching globals before locals in one specific case), this is needed for backwards compatibility.
2021-04-26 10:31:21 -07:00
Pablo Galindo b0544ba77c
bpo-38605: Revert making 'from __future__ import annotations' the default (GH-25490)
This reverts commits 044a1048ca and 1be456ae9d, adapting the code to changes that happened after it.
2021-04-21 12:41:19 +01:00
Victor Stinner a6a5c91b1e
bpo-40443: Remove unused imports (GH-25429)
* pyclbr no longer uses copy
* typing no longer uses ast

Issue discovered by pyflakes.
2021-04-16 11:26:06 +02:00
Karthikeyan Singaravelan a9cf69df2e
bpo-41515: Fix KeyError raised in get_type_hints (GH-25352)
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Co-authored-by: efahl <36704995+efahl@users.noreply.github.com>
2021-04-12 11:17:25 -07:00
Ken Jin 852150ddfe
bpo-42904: Fix get_type_hints for class local namespaces (GH-24201) 2021-04-12 10:23:12 -07:00
Jelle Zijlstra 9045919bfa
bpo-43772: Fix TypeVar.__ror__ (GH-25339) 2021-04-10 20:00:05 -07:00