summaryrefslogtreecommitdiffstats
path: root/Lib/typing.py
Commit message (Collapse)AuthorAgeFilesLines
* gh-88965: typing: fix type substitution of a list of types after initial ↵Nikita Sobolev2023-03-231-7/+26
| | | | | | | | | | | | | | | | | | | `ParamSpec` substitution (#102808) Previously, this used to fail: ```py from typing import * T = TypeVar("T") P = ParamSpec("P") class X(Generic[P]): f: Callable[P, int] Y = X[[int, T]] Z = Y[str] ``` Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* Add comments to `{typing,_collections_abc}._type_repr` about each other ↵Nikita Sobolev2023-03-161-0/+3
| | | | | (#102752) Remove `if` condition in `_collections_abc._type_repr` that's no longer needed, bringing it in sync with `typing._type_repr`.
* gh-102615: Use `list` instead of `tuple` in `repr` of paramspec (#102637)Nikita Sobolev2023-03-151-3/+4
| | | Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* gh-101561: Add typing.override decorator (#101564)Steven Troxler2023-02-271-0/+41
| | | | Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* gh-101015: Fix `typing.get_type_hints` with unpacked `*tuple` (PEP 646) ↵Nikita Sobolev2023-01-231-1/+4
| | | | (#101031)
* gh-86682: Adds sys._getframemodulename as an alternative to using _getframe ↵Steve Dower2023-01-131-2/+6
| | | | | (GH-99520) Also updates calls in collections, doctest, enum, and typing modules to use _getframemodulename first when available.
* Correct typo in typing.py (#100423)david-why2022-12-221-1/+1
| | | | In the docstring of `ParamSpec`, the name of `P = ParamSpec('P')` was mistakenly written as `'T'`.
* gh-99957: Add `frozen_default` parameter on `dataclass_transform` (#99958)Erik De Bonte2022-12-061-0/+4
|
* gh-98253: Break potential reference cycles in external code worsened by ↵Wenzel Jakob2022-11-301-3/+11
| | | | typing.py lru_cache (#98591)
* gh-99344, gh-99379, gh-99382: Fix issues in substitution of ParamSpec and ↵Serhiy Storchaka2022-11-291-41/+30
| | | | | | | | | | | TypeVarTuple (GH-99412) * Fix substitution of TypeVarTuple and ParamSpec together in user generics. * Fix substitution of ParamSpec followed by TypeVarTuple in generic aliases. * Check the number of arguments in substitution in user generics containing a TypeVarTuple and one or more TypeVar.
* gh-98852: Fix subscription of type aliases (GH-98920)Serhiy Storchaka2022-11-011-0/+4
| | | | | Fix subscription of type aliases containing bare generic types or types like TypeVar: for example tuple[A, T][int] and tuple[TypeVar, T][int], where A is a generic type, and T is a type variable.
* GH-96079 Fix missing field name for _AnnotatedAlias (#96080)Anh71me2022-08-311-1/+4
|
* gh-95987: Fix `repr` of `Any` type subclasses (#96412)Nikita Sobolev2022-08-301-1/+3
|
* gh-96385: Correctly raise error on `[*T, *V]` substitution (GH-96386)Nikita Sobolev2022-08-301-1/+1
|
* docs: typing.Self, fix typo (GH-94771)Max Zhenzhera2022-07-121-1/+1
| | | | | * fix typo - double spelled word 'use' * change methods names to the infinitive form
* gh-94607: Fix subclassing generics (GH-94610)Ken Jin2022-07-091-0/+3
| | | Co-authored-by: Serhiy Storchaka <3659035+serhiy-storchaka@users.noreply.github.com>
* bpo-46642: Explicitly disallow subclassing of instaces of TypeVar, ↵Gregory Beauregard2022-06-251-0/+12
| | | | | | | | ParamSpec, etc (GH-31148) The existing test covering this case passed only incidentally. We explicitly disallow doing this and add a proper error message. Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* gh-89828: Do not relay the __class__ attribute in GenericAlias (#93754)Serhiy Storchaka2022-06-181-1/+1
| | | | | list[int].__class__ returned type, and isinstance(list[int], type) returned True. It caused numerous problems in code that checks isinstance(x, type).
* gh-91162: Support splitting of unpacked arbitrary-length tuple over TypeVar ↵Serhiy Storchaka2022-06-121-64/+46
| | | | | | | | | and TypeVarTuple parameters (alt) (GH-93412) For example: A[T, *Ts][*tuple[int, ...]] -> A[int, *tuple[int, ...]] A[*Ts, T][*tuple[int, ...]] -> A[*tuple[int, ...], int]
* gh-91860: documentation for typing.dataclass_transform (#92768)Shantanu2022-05-201-7/+10
| | | Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* Add `__slots__` to `typing._NotIterable` (GH-92570)Alex Waygood2022-05-101-0/+1
|
* gh-91162: Fix substitution of unpacked tuples in generic aliases (GH-92335)Serhiy Storchaka2022-05-081-24/+52
|
* gh-92261: Disallow iteration of Union (and other special forms) (GH-92262)Matthew Rahtz2022-05-081-5/+20
|
* bpo-44863: Allow generic typing.TypedDict (#27663)Samodya Abey2022-05-031-4/+11
| | | | | | Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* gh-91621: Fix typing.get_type_hints for collections.abc.Callable (#91656)Shantanu2022-05-021-3/+23
| | | | | | This mirrors logic in typing.get_args. The trickiness comes from how we flatten args in collections.abc.Callable, see https://bugs.python.org/issue42195
* bpo-43923: Add support for generic typing.NamedTuple (#92027)Serhiy Storchaka2022-05-021-4/+13
|
* bpo-43224: Implement substitution of unpacked TypeVarTuple in C (GH-31828)Serhiy Storchaka2022-04-301-3/+7
| | | | Co-authored-by: Matthew Rahtz <mrahtz@gmail.com>
* bpo-44791: Accept ellipsis as the last argument of typing.Concatenate (#30969)Serhiy Storchaka2022-04-291-5/+2
|
* gh-91860: Add typing.dataclass_transform (PEP 681) (#91861)Jelle Zijlstra2022-04-261-0/+79
| | | | | | | Copied from typing-extensions (python/typing#1054, python/typing#1120). Documentation is intentionally omitted, so we can focus on getting the runtime part in before the feature freeze.
* gh-90633: Improve error and docs for typing.assert_never (#91720)Jelle Zijlstra2022-04-251-1/+7
| | | | | Closes #90633 Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* bpo-43224: Implement pickling of TypeVarTuples (#32119)Matthew Rahtz2022-04-221-6/+19
| | | Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* gh-89263: Add typing.get_overloads (GH-31716)Jelle Zijlstra2022-04-161-0/+34
| | | | | | | Based on suggestions by Guido van Rossum, Spencer Brown, and Alex Waygood. Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com> Co-authored-by: Guido van Rossum <gvanrossum@gmail.com> Co-authored-by: Ken Jin <kenjin4096@gmail.com>
* bpo-43224: Add tests for TypeVarTuple substitution in Annotated (GH-31846)Matthew Rahtz2022-04-161-0/+14
|
* bpo-43224: Forbid TypeVar substitution with Unpack (GH-32031)Serhiy Storchaka2022-04-131-0/+2
|
* gh-91243: Add typing.Required and NotRequired (PEP 655) (GH-32419)Jelle Zijlstra2022-04-121-4/+59
| | | | | | | | | | | I talked to @davidfstr and I offered to implement the runtime part of PEP 655 to make sure we can get it in before the feature freeze. We're going to defer the documentation to a separate PR, because it can wait until after the feature freeze. The runtime implementation conveniently already exists in typing-extensions, so I largely copied that. Co-authored-by: David Foster <david@dafoster.net>
* bpo-44807: Allow Protocol classes to define __init__ (GH-31628)Adrian Garcia Badaracco2022-04-111-1/+2
| | | Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* bpo-47088: Add typing.LiteralString (PEP 675) (GH-32064)Jelle Zijlstra2022-04-051-1/+30
| | | Co-authored-by: Nick Pope <nick@nickpope.me.uk>
* bpo-46998: Allow subclassing Any at runtime (GH-31841)Shantanu2022-04-051-4/+17
| | | Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* bpo-43224: Implement PEP 646 grammar changes (GH-31018)Matthew Rahtz2022-03-261-1/+10
| | | Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* bpo-46480: rephrase typing.assert_type docs (GH-32069)Shantanu2022-03-241-1/+1
| | | | | | | | | The goal here is to reduce potential confusion between `assert_type(val, type)` and `assert isinstance(val, typ)`. The former is meant to ask a type checker to confirm a fact, the latter is meant to tell a type checker a fact. The behaviour of the latter more closely resembles what I'd expect from the prior phrasing of "assert [something] to the type checker".
* bpo-43224: Add TypeVarTuple.__name__ (GH-31954)Jelle Zijlstra2022-03-181-2/+2
| | | | I noticed that TypeVar and ParamSpec put their name in a __name__ attribute, but TypeVarTuple doesn't. Let's be consistent.
* bpo-46981: Remove typing._TypingEmpty (GH-31836)Serhiy Storchaka2022-03-171-10/+0
| | | | | * get_args(Tuple[()]) now returns () instead of ((),). * Tuple[Unpack[Ts]][()] now returns the result equal to Tuple[()].
* bpo-46480: add typing.assert_type (GH-30843)Jelle Zijlstra2022-03-171-0/+17
| | | | Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com> Co-authored-by: David Foster <david@dafoster.net>
* bpo-46644: Remove callable() requirement from typing._type_check (GH-31151)Gregory Beauregard2022-03-121-4/+1
| | | We also remove all the tests that check for integer literals.
* bpo-43224: Implement substitution of unpacked TypeVarTuple (GH-31800)Serhiy Storchaka2022-03-111-17/+32
|
* bpo-44796: Unify TypeVar and ParamSpec substitution (GH-31143)Serhiy Storchaka2022-03-111-46/+49
| | | | | | Add methods __typing_subst__() in TypeVar and ParamSpec. Simplify code by using more object-oriented approach, especially the C code for types.GenericAlias and the Python code for collections.abc.Callable.
* bpo-46581: Propagate private vars via _GenericAlias.copy_with (GH-31061)Matt Bogosian2022-03-101-7/+6
| | | | | | | | | | 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>
* bpo-43224: Implement PEP 646 changes to typing.py (GH-31021)Matthew Rahtz2022-03-081-21/+214
| | | | Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* bpo-46170: Improve the error message when subclassing NewType (GH-30268)James Hilton-Balfe2022-03-081-0/+15
| | | | | Co-authored-by: Alex Waygood <alex.waygood@gmail.com> Co-authored-by: Nikita Sobolev <mail@sobolevn.me> Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
* bpo-41370: Evaluate strings as forward refs in PEP 585 generics (GH-30900)Niklas Rosenstein2022-03-071-0/+6
| | | | | | This removes discrepancy between list["int"] and List["int"]. Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>