Commit Graph

138 Commits

Author SHA1 Message Date
Miss Islington (bot) d452b2963b
bpo-45280: Add test for empty `NamedTuple` in `test_typing` (GH-28559) (GH-28571)
Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
(cherry picked from commit f56268a2cd)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2021-09-26 19:09:50 +02: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) 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) 76903ff9ce
bpo-44794: Merge tests for typing.Callable and collection.abc.Callable (GH-27507)
(cherry picked from commit be4cb9089a)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2021-07-31 10:25:22 -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) 472997659b
bpo-44662: Add ability to annotate types.Union (GH-27214) (GH-27461)
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
(cherry picked from commit 8182c8329c)

Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
2021-07-30 11:31:54 +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) e8c01749c0
bpo-44353: Improve tests covering typing.NewType pickling (GH-27302) (GH-27328)
(cherry picked from commit a22b05da87)

Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
2021-07-24 12:29:19 +02: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) 9ae5ba7dbf
bpo-44353: Add test to cover __or__ of two NewType (GH-27259) (#27261)
(cherry picked from commit 4868b94c60)

Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
2021-07-20 18:06:38 +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) 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
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
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
Karthikeyan Singaravelan eb77133564
bpo41515: Fix assert in test which throws SyntaxWarning. (#25379) 2021-04-13 06:54:23 -07: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
Jelle Zijlstra 522433601a
bpo-43783: Add ParamSpecArgs/Kwargs (GH-25298) 2021-04-10 19:57:05 -07:00
Ken Jin efb1f0918f
bpo-42740: Support PEP 604, 612 for typing.py get_args and get_origin (GH-23942) 2020-12-28 18:26:19 -08:00
Ken Jin 4140f10a16
bpo-42740: Fix get_args for PEP 585 collections.abc.Callable (GH-23963)
PR 1/2. Needs backport to 3.9.
2020-12-28 12:06:19 -08:00
kj 73607be686
bpo-41559: Implement PEP 612 - Add ParamSpec and Concatenate to typing (#23702) 2020-12-23 20:33:48 -08:00
kj 463c7d3d14
bpo-42195: Ensure consistency of Callable's __args__ in collections.abc and typing (GH-23060) 2020-12-13 10:38:24 -08:00
Alex Grönholm 67b769f515
bpo-42059: Fix required/optional keys for TypedDict(..., total=False) (GH-22736) 2020-12-10 13:49:05 -08:00
Yurii Karabas 1b54077ff6
bpo-42345: Fix hash implementation of typing.Literal (GH-23383)
Fix hash implementation of `typing.Literal`.

Update docs regarding `typing.Litaral` caching.

Base implementation was done in PR #23294.
2020-11-19 08:17:38 -08:00
Yurii Karabas f03d318ca4
bpo-42345: Fix three issues with typing.Literal parameters (GH-23294)
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.
2020-11-16 18:23:19 -08:00
kj 1f7dfb277e
bpo-42233: Correctly repr GenericAlias when used with typing module (GH-23081)
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
2020-11-01 10:13:38 -08:00
Mikhail Golubev 4f3c25043d
bpo-41923: PEP 613: Add TypeAlias to typing module (#22532)
This special marker annotation is intended to help in distinguishing
proper PEP 484-compliant type aliases from regular top-level variable
assignments.
2020-10-07 14:44:31 -07:00
Batuhan Taskaya 044a1048ca
bpo-38605: Make 'from __future__ import annotations' the default (GH-20434)
The hard part was making all the tests pass; there are some subtle issues here, because apparently the future import wasn't tested very thoroughly in previous Python versions.

For example, `inspect.signature()` returned type objects normally (except for forward references), but strings with the future import. We changed it to try and return type objects by calling `typing.get_type_hints()`, but fall back on returning strings if that function fails (which it may do if there are future references in the annotations that require passing in a specific namespace to resolve).
2020-10-06 13:03:02 -07:00
Patrick Reader 0705ec8a14
bpo-41792: Add is_typeddict function to typing.py (GH-22254)
Closes issue41792.

Also closes https://github.com/python/typing/issues/751.
2020-09-15 21:58:32 -07:00
Maggie Moss 1b4552c5e8
bpo-41428: Implementation for PEP 604 (GH-21515)
See https://www.python.org/dev/peps/pep-0604/ for more information.

Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
2020-09-09 21:23:24 +01:00
Victor Stinner 0ee0b2938c
bpo-41521: Replace whitelist/blacklist with allowlist/denylist (GH-21823)
Rename 5 test method names in test_codecs and test_typing.
2020-08-11 15:28:43 +02:00
wyfo 653f420b53
bpo-41341: Recursive evaluation of ForwardRef in get_type_hints (#21553)
The issue raised by recursive evaluation is infinite recursion with
recursive types. In that case, only the first recursive ForwardRef is
evaluated.
2020-07-22 12:47:28 -07:00
Zackery Spytz 7fed75597f
bpo-39168: Remove the __new__ method of typing.Generic (GH-21327)
Automerge-Triggered-By: @gvanrossum
2020-07-04 22:07:43 -07:00
Serhiy Storchaka 0122d48681
bpo-40397: Fix subscription of nested generic alias without parameters. (GH-20021) 2020-05-10 13:39:40 +03:00
Vlad Serebrennikov 138a9b9c2a
bpo-40389: Improve repr of typing.Optional (#19714) 2020-04-29 18:06:39 -07:00
Victor Stinner 57572b103e
bpo-40443: Remove unused imports in tests (GH-19805) 2020-04-30 01:48:37 +02:00