summaryrefslogtreecommitdiffstats
path: root/Lib/typing.py
Commit message (Collapse)AuthorAgeFilesLines
* gh-96385: Correctly raise error on `[*T, *V]` substitution (GH-96386) (#96407)Miss Islington (bot)2022-08-301-1/+1
| | | | | | | (cherry picked from commit 75177358a62afeabd1d3aa0e9f395c2b9d4495ca) Co-authored-by: Nikita Sobolev <mail@sobolevn.me> Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
* docs: typing.Self, fix typo (GH-94771)Miss Islington (bot)2022-07-121-1/+1
| | | | | | | | * fix typo - double spelled word 'use' * change methods names to the infinitive form (cherry picked from commit 90a6e56e5663233fe986331ef3f10422fe57dcbc) Co-authored-by: Max Zhenzhera <59729293+maxzhenzhera@users.noreply.github.com>
* gh-94607: Fix subclassing generics (GH-94610)Miss Islington (bot)2022-07-091-0/+3
| | | | | | Co-authored-by: Serhiy Storchaka <3659035+serhiy-storchaka@users.noreply.github.com> (cherry picked from commit 6442a9dd212fa18343db21849cf05c0181662c1f) Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
* gh-89828: Do not relay the __class__ attribute in GenericAlias (GH-93754)Miss Islington (bot)2022-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). (cherry picked from commit f9433fff476aa13af9cb314fcc6962055faa4085) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* [3.11] gh-91162: Support splitting of unpacked arbitrary-length tuple over ↵Miss Islington (bot)2022-06-141-64/+46
| | | | | | | | | | | | TypeVar and TypeVarTuple parameters (alt) (GH-93412) (GH-93746) For example: A[T, *Ts][*tuple[int, ...]] -> A[int, *tuple[int, ...]] A[*Ts, T][*tuple[int, ...]] -> A[*tuple[int, ...], int] (cherry picked from commit 3473817106c23eca7341c931453da0341c367e1d) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* [3.11] gh-91162: Fix substitution of unpacked tuples in generic aliases ↵Miss Islington (bot)2022-06-011-24/+52
| | | | | | | | | | | | | (GH-92335) (#92484) * gh-91162: Fix substitution of unpacked tuples in generic aliases (GH-92335) (cherry picked from commit 9d25db9db1617f012d7dba118b5b8f2b9e25e116) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> * Regenerate ABI file Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
* gh-91860: documentation for typing.dataclass_transform (GH-92768)Miss Islington (bot)2022-05-201-7/+10
| | | | | | Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com> (cherry picked from commit f20a6a54fb041507a334ad71706974960d1b473f) Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
* Add `__slots__` to `typing._NotIterable` (GH-92570)Miss Islington (bot)2022-05-101-0/+1
| | | | | (cherry picked from commit eef47d5bc79469c2d5328d6f5a9732e44a49dd5a) Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* gh-92261: Disallow iteration of Union (and other special forms) (GH-92262) ↵Miss Islington (bot)2022-05-101-5/+20
| | | | | | | | (GH-92582) (cherry picked from commit 4739997e141c4c84bd2241d4d887c3c658d92700) Co-authored-by: Matthew Rahtz <matthew.rahtz@gmail.com>
* 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>
* Lib/typing.py copy edits originating from GH-31061 (#31684)Matt Bogosian2022-03-051-3/+3
|
* bpo-46643: Fix stringized P.args/P.kwargs with get_type_hints (GH-31238)Gregory Beauregard2022-03-031-1/+2
|
* bpo-46195: Do not add `Optional` in `get_type_hints` (GH-30304)Nikita Sobolev2022-03-021-27/+2
| | | | Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* bpo-46571: improve `typing.no_type_check` to skip foreign objects (GH-31042)Nikita Sobolev2022-02-191-5/+15
| | | | | | | | | | | | There are several changes: 1. We now don't explicitly check for any base / sub types, because new name check covers it 2. I've also checked that `no_type_check` do not modify foreign functions. It was the same as with `type`s 3. I've also covered `except TypeError` in `no_type_check` with a simple test case, it was not covered at all 4. I also felt like adding `lambda` test is a good idea: because `lambda` is a bit of both in class bodies: a function and an assignment <!-- issue-number: [bpo-46571](https://bugs.python.org/issue46571) --> https://bugs.python.org/issue46571 <!-- /issue-number -->
* bpo-46333: Honor `module` parameter in ForwardRef (GH-30536)aha792022-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>
* bpo-46066: Deprecate kwargs syntax for TypedDict definitions (GH-31126)97littleleaf112022-02-171-4/+11
| | | | | | Closes python/typing#981 https://bugs.python.org/issue46066
* bpo-46333: include `module` in `ForwardRef.__repr__` (#31283)aha792022-02-121-1/+5
| | | | | | | | The module parameter carries semantic information about the forward ref. Show to the user that forward refs with same argument but different module are different. Co-authored-by: Andreas Hangauer <andreas.hangauer@siemens.com> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
* bpo-46475: Add typing.Never and typing.assert_never (GH-30842)Jelle Zijlstra2022-02-081-4/+60
|
* bpo-46676: Make ParamSpec args and kwargs equal to themselves (GH-31203)Gregory Beauregard2022-02-081-0/+10
|
* bpo-46534: Implement PEP 673 Self in typing.py (GH-30924)James Hilton-Balfe2022-02-071-1/+23
| | | | Co-authored-by: Pradeep Kumar Srinivasan <gohanpra@gmail.com> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* bpo-46589: Improve documentation for typing._GenericAlias (GH-31026)Matthew Rahtz2022-02-071-32/+110
| | | (These should arguably be docstrings per convention in the rest of the file, but it doesn't really matter.)
* bpo-46655: allow stringized TypeAlias with get_type_hints (GH-31156)Gregory Beauregard2022-02-061-1/+1
|
* Fix __init_subclass__ using self instead of class (#31135)Gregory Beauregard2022-02-051-1/+1
|
* bpo-46414: Add typing.reveal_type (#30646)Jelle Zijlstra2022-02-021-0/+21
| | | | Co-authored-by: Nikita Sobolev <mail@sobolevn.me>