summaryrefslogtreecommitdiffstats
path: root/Lib/typing.py
Commit message (Collapse)AuthorAgeFilesLines
* gh-114053: Fix another edge case involving `get_type_hints`, PEP 695 and PEP ↵Alex Waygood2024-06-251-7/+16
| | | | 563 (#120272)
* gh-119180: PEP 649 compiler changes (#119361)Jelle Zijlstra2024-06-111-4/+19
|
* gh-119180: PEP 649: Add __annotate__ attributes (#119209)Jelle Zijlstra2024-05-221-0/+1
|
* Rename typing._collect_parameters (#118900)Jelle Zijlstra2024-05-101-7/+17
| | | | | | | | | | | Unfortunately, released versions of typing_extensions monkeypatch this function without the extra parameter, which makes it so things break badly if current main is used with typing_extensions. Fortunately, the monkeypatching is not needed on Python 3.13, because CPython now implements PEP 696. By renaming the function, we prevent the monkeypatch from breaking typing.py internals. We keep the old name (raising a DeprecationWarning) to help other external users who call it.
* gh-118803: Remove `ByteString` from `typing` and `collections.abc` (#118804)Nikita Sobolev2024-05-081-19/+0
|
* gh-118772: Allow TypeVars without a default to follow those with a default ↵Jelle Zijlstra2024-05-081-10/+15
| | | | when constructing aliases (#118774)
* gh-118660: Add second type parameter to (Async)ContextManager (#118681)Jelle Zijlstra2024-05-071-1/+1
| | | Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* gh-118418: Deprecate failing to pass a value to the *type_params* parameter ↵Alex Waygood2024-05-071-11/+30
| | | | of some private `typing` APIs (#118695)
* gh-118647: Add defaults to typing.Generator and typing.AsyncGenerator (#118648)Jelle Zijlstra2024-05-061-5/+16
| | | | Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com> Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
* gh-118465: Add __firstlineno__ attribute to class (GH-118475)Serhiy Storchaka2024-05-061-1/+1
| | | | It is set by compiler with the line number of the first line of the class definition.
* gh-116126: Implement PEP 696 (#116129)Jelle Zijlstra2024-05-031-24/+71
| | | | | Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
* gh-118418: Use a default value for `type_params` in `typing._eval_type` ↵Nikita Sobolev2024-04-301-2/+2
| | | | (#118431)
* gh-118168: Fix Unpack interaction with builtin aliases (#118169)Jelle Zijlstra2024-04-231-2/+3
| | | Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* gh-114053: Fix bad interaction of PEP-695, PEP-563 and ``get_type_hints`` ↵Alex Waygood2024-04-191-8/+27
| | | | | | (#118009) Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* gh-117516: Implement typing.TypeIs (#117517)Jelle Zijlstra2024-04-091-11/+85
| | | | | | See PEP 742. Co-authored-by: Carl Meyer <carl@oddbird.net> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
* gh-117521: Improve typing.TypeGuard docstring (#117522)Jelle Zijlstra2024-04-041-11/+14
|
* gh-117110: Fix subclasses of typing.Any with custom constructors (#117111)傅立业(Chris Fu)2024-03-291-1/+1
|
* gh-115775: Compiler adds __static_attributes__ field to classes (#115913)Irit Katriel2024-03-261-1/+1
|
* gh-116127: PEP-705: Add `ReadOnly` support for `TypedDict` (#116350)Nikita Sobolev2024-03-121-10/+73
| | | Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* gh-89547: Support for nesting special forms like Final (#116096)Mehdi Drissi2024-03-121-2/+2
|
* gh-116325: Raise `SyntaxError` rather than `IndexError` on ForwardRef with ↵Nikita Sobolev2024-03-051-1/+1
| | | | empty string arg (#116341)
* gh-112281: Allow `Union` with unhashable `Annotated` metadata (#112283)Nikita Sobolev2024-03-011-14/+31
| | | | Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* gh-115165: Fix `typing.Annotated` for immutable types (#115213)dave-shawley2024-02-091-1/+3
| | | | The return value from an annotated callable can raise any exception from __setattr__ for the `__orig_class__` property.
* gh-112903: Handle non-types in _BaseGenericAlias.__mro_entries__() (#115191)Carl Meyer2024-02-091-1/+21
| | | Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* gh-113320: Reduce the number of dangerous `getattr()` calls when ↵Alex Waygood2024-01-051-18/+28
| | | | | | | constructing protocol classes (#113401) - Only attempt to figure out whether protocol members are "method members" or not if the class is marked as a runtime protocol. This information is irrelevant for non-runtime protocols; we can safely skip the risky introspection for them. - Only do the risky getattr() calls in one place (the runtime_checkable class decorator), rather than in three places (_ProtocolMeta.__init__, _ProtocolMeta.__instancecheck__ and _ProtocolMeta.__subclasscheck__). This reduces the number of locations in typing.py where the risky introspection could go wrong. - For runtime protocols, if determining whether a protocol member is callable or not fails, give a better error message. I think it's reasonable for us to reject runtime protocols that have members which raise strange exceptions when you try to access them. PEP-544 clearly states that all protocol member must be callable for issubclass() calls against the protocol to be valid -- and if a member raises when we try to access it, there's no way for us to figure out whether it's a callable member or not!
* gh-113255: Clarify docs for `typing.reveal_type` (#113286)Kir2023-12-201-2/+2
| | | Co-authored-by: AlexWaygood <alex.waygood@gmail.com>
* gh-74690: Avoid a costly type check where possible in ↵Alex Waygood2023-12-041-3/+19
| | | | `_ProtocolMeta.__subclasscheck__` (#112717)
* gh-74690: Optimise `isinstance()` and `issubclass()` calls against ↵Alex Waygood2023-12-041-3/+11
| | | | runtime-checkable protocols by avoiding costly `super()` calls (#112708)
* gh-112618: Make `Annotated` cache typed (#112619)Nikita Sobolev2023-12-021-5/+6
| | | Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* gh-112509: Fix keys being present in both required_keys and optional_keys in ↵Jelle Zijlstra2023-11-291-5/+20
| | | | | TypedDict (#112512) Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* gh-111874: Call `__set_name__` on objects that define the method inside a ↵Alex Waygood2023-11-271-3/+18
| | | | | `typing.NamedTuple` class dictionary as part of the creation of that class (#111876) Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* gh-112345: `typing.Protocol`: Let failed subclasscheck show non-method ↵Randolf Scholz2023-11-241-1/+6
| | | | | members (#112344) Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* gh-112194: Convert more examples to doctests in `typing.py` (#112195)Nikita Sobolev2023-11-171-31/+43
| | | Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* gh-112155: Run `typing.py` doctests as part of `test_typing` (#112156)Nikita Sobolev2023-11-161-2/+2
|
* GH-112152: Fix typo in `typing.override` docstring (#112158)Qua272023-11-161-1/+1
|
* gh-110682: Ignore `__match_args__` from `__instancecheck__` in protocols ↵Nikita Sobolev2023-10-121-1/+2
| | | | | (#110683) Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* gh-110180: Remove unused `_PickleUsingNameMixin` class from `typing` (#110181)Alex Waygood2023-10-011-7/+0
|
* gh-109653: `typing.py`: improve import time by creating soft-deprecated ↵Alex Waygood2023-09-231-8/+18
| | | | | members on demand (#109651) Co-authored-by: Thomas Grainger <tagrain@gmail.com>
* gh-109543: Remove unnecessary hasattr check (#109544)Jelle Zijlstra2023-09-201-2/+1
| | | | Also added a new test case covering the scenario I thought this might be about.
* gh-105509: Simplify implementation of `typing.Annotated` (#105510)Alex Waygood2023-09-011-25/+13
|
* gh-106309: Deprecate typing.no_type_check_decorator (#106312)Alex Waygood2023-07-131-0/+2
|
* gh-105974: Revert unintentional behaviour change for protocols with ↵Alex Waygood2023-06-231-32/+33
| | | | non-callable members and custom `__subclasshook__` methods (#105976)
* gh-105570: Deprecate unusual ways of creating empty TypedDicts (#105780)Alex Waygood2023-06-141-2/+17
| | | Deprecate two methods of creating typing.TypedDict classes with 0 fields using the functional syntax: `TD = TypedDict("TD")` and `TD = TypedDict("TD", None)`. Both will be disallowed in Python 3.15. To create a TypedDict class with 0 fields, either use `class TD(TypedDict): pass` or `TD = TypedDict("TD", {})`.
* gh-105566: Deprecate unusual ways of creating `typing.NamedTuple` classes ↵Alex Waygood2023-06-141-3/+45
| | | | | | | (#105609) Deprecate creating a typing.NamedTuple class using keyword arguments to denote the fields (`NT = NamedTuple("NT", x=int, y=str)`). This will be disallowed in Python 3.15. Use the class-based syntax or the functional syntax instead. Two methods of creating `NamedTuple` classes with 0 fields using the functional syntax are also deprecated, and will be disallowed in Python 3.15: `NT = NamedTuple("NT")` and `NT = NamedTuple("NT", None)`. To create a `NamedTuple` class with 0 fields, either use `class NT(NamedTuple): pass` or `NT = NamedTuple("NT", [])`.
* gh-104873: Add typing.get_protocol_members and typing.is_protocol (#104878)Jelle Zijlstra2023-06-141-0/+42
| | | Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* Miscellaneous improvements to the typing docs (#105529)Alex Waygood2023-06-091-6/+6
| | | Mostly, these are changes so that we use shorter sentences and shorter paragraphs. In particular, I've tried to make the first sentence introducing each object in the typing API short and declarative.
* Further improve docs for `typing.Annotated` (#105498)Alex Waygood2023-06-081-6/+8
|
* typing: Improve documentation of generic classes and aliases (#105369)Alex Waygood2023-06-071-3/+5
|
* gh-105430: Remove `typing._Immutable` unused internal helper (#105434)Nikita Sobolev2023-06-071-11/+0
|
* gh-105286: Further improvements to `typing.py` docstrings (#105363)Alex Waygood2023-06-071-25/+43
|