summaryrefslogtreecommitdiffstats
path: root/Lib/typing.py
Commit message (Collapse)AuthorAgeFilesLines
* [3.12] gh-117521: Improve typing.TypeGuard docstring (GH-117522) (#117538)Miss Islington (bot)2024-04-041-11/+14
| | | | | (cherry picked from commit b32789ccb91bbe43e88193f68b1364a8da6d9866) Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* [3.12] gh-117110: Fix subclasses of typing.Any with custom constructors ↵Miss Islington (bot)2024-03-291-1/+1
| | | | | | | | (GH-117111) (#117357) gh-117110: Fix subclasses of typing.Any with custom constructors (GH-117111) (cherry picked from commit 8eec7ed714e65d616573b7331780b0aa43c6ed6a) Co-authored-by: 傅立业(Chris Fu) <17433201@qq.com>
* [3.12] gh-116325: Raise `SyntaxError` rather than `IndexError` on ForwardRef ↵Miss Islington (bot)2024-03-051-1/+1
| | | | | | | | with empty string arg (GH-116341) (#116347) gh-116325: Raise `SyntaxError` rather than `IndexError` on ForwardRef with empty string arg (GH-116341) (cherry picked from commit a29998a06bf75264c3faaeeec4584a5f75b45a1f) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
* [3.12] gh-112281: Allow `Union` with unhashable `Annotated` metadata ↵Miss Islington (bot)2024-03-011-14/+31
| | | | | | | (GH-112283) (#116213) Co-authored-by: Nikita Sobolev <mail@sobolevn.me> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* [3.12] gh-115570: Fix DeprecationWarnings in test_typing (#115571) (#115574)Jelle Zijlstra2024-02-161-2/+2
| | | Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* [3.12] gh-115165: Fix `typing.Annotated` for immutable types (GH-115213) ↵Miss Islington (bot)2024-02-091-1/+3
| | | | | | | | | | | (#115227) gh-115165: Fix `typing.Annotated` for immutable types (GH-115213) The return value from an annotated callable can raise any exception from __setattr__ for the `__orig_class__` property. (cherry picked from commit 564385612cdf72c2fa8e629a68225fb2cd3b3d99) Co-authored-by: dave-shawley <daveshawley@gmail.com>
* [3.12] gh-113320: Reduce the number of dangerous `getattr()` calls when ↵Alex Waygood2024-01-051-13/+26
| | | | | | | | | constructing protocol classes (#113401) (#113722) - 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! (cherry-picked from commit ed6ea3ea79)
* [3.12] gh-113255: Clarify docs for `typing.reveal_type` (GH-113286) (#113323)Miss Islington (bot)2023-12-201-2/+2
| | | | | | | gh-113255: Clarify docs for `typing.reveal_type` (GH-113286) (cherry picked from commit 11ee912327ef51100d2a6b990249f25b6b1b435d) Co-authored-by: Kir <note351@hotmail.com> Co-authored-by: AlexWaygood <alex.waygood@gmail.com>
* [3.12] gh-112618: Make Annotated cache typed (#112619) (#112628)Alex Waygood2023-12-031-2/+7
|
* [3.12] gh-112509: Fix keys being present in both required_keys and ↵Miss Islington (bot)2023-11-291-5/+20
| | | | | | | | optional_keys in TypedDict (GH-112512) (#112530) (cherry picked from commit 403886942376210662610627b01fea6acd77d331) Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* [3.12] gh-112194: Convert more examples to doctests in `typing.py` ↵Miss Islington (bot)2023-11-171-31/+43
| | | | | | | | | (GH-112195) (#112208) gh-112194: Convert more examples to doctests in `typing.py` (GH-112195) (cherry picked from commit 949b2cc6eae6ef4f3312dfd4e2650a138446fe77) Co-authored-by: Nikita Sobolev <mail@sobolevn.me> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* [3.12] GH-112152: Fix typo in `typing.override` docstring (GH-112158) (#112162)Miss Islington (bot)2023-11-161-1/+1
| | | | | | GH-112152: Fix typo in `typing.override` docstring (GH-112158) (cherry picked from commit 12c7e9d573de57343cf018fb4e67521aba46c90f) Co-authored-by: Qua27 <92877777+Qua27@users.noreply.github.com>
* [3.12] gh-105974: Revert unintentional behaviour change for protocols with ↵Miss Islington (bot)2023-06-231-32/+33
| | | | | | | | non-callable members and custom `__subclasshook__` methods (GH-105976) (#106032) gh-105974: Revert unintentional behaviour change for protocols with non-callable members and custom `__subclasshook__` methods (GH-105976) (cherry picked from commit 9499b0f138cc53b9a2590350d0b545d2f69ee126) Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* [3.12] Miscellaneous improvements to the typing docs (GH-105529) (#105567)Miss Islington (bot)2023-06-091-6/+6
| | | | | | | | Miscellaneous improvements to the typing docs (GH-105529) 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. (cherry picked from commit 8e755923c97d689ba7c7fe8deb50c1b169263264) Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* [3.12] Further improve docs for `typing.Annotated` (GH-105498) (#105503)Miss Islington (bot)2023-06-081-6/+8
| | | | | | Further improve docs for `typing.Annotated` (GH-105498) (cherry picked from commit d213c2990f0db62ed39fc5468977f989c2658675) Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* [3.12] typing: Improve documentation of generic classes and aliases ↵Miss Islington (bot)2023-06-071-3/+5
| | | | | | | | (GH-105369) (#105453) typing: Improve documentation of generic classes and aliases (GH-105369) (cherry picked from commit d63a7c3694d5c4484fcaa01c33590b1d4bc2559e) Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* [3.12] gh-105430: Remove `typing._Immutable` unused internal helper ↵Miss Islington (bot)2023-06-071-11/+0
| | | | | | | | (GH-105434) (#105451) gh-105430: Remove `typing._Immutable` unused internal helper (GH-105434) (cherry picked from commit 18309ad94bb1ae0b092f34dc3fd54199876a6ebd) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
* [3.12] gh-105286: Further improvements to `typing.py` docstrings (GH-105363) ↵Miss Islington (bot)2023-06-071-25/+43
| | | | | | | | (#105416) gh-105286: Further improvements to `typing.py` docstrings (GH-105363) (cherry picked from commit 9a89f1bf1e7bb819fe7240be779c99a84f47ea46) Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* [3.12] gh-105286: Improve `typing.py` docstrings (#105287) (#105319)Alex Waygood2023-06-051-220/+253
| | | | | | gh-105286: Improve `typing.py` docstrings (#105287) Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
* [3.12] gh-105280: Ensure `isinstance([], collections.abc.Mapping)` always ↵Miss Islington (bot)2023-06-051-8/+20
| | | | | | | | evaluates to `False` (GH-105281) (#105318) gh-105280: Ensure `isinstance([], collections.abc.Mapping)` always evaluates to `False` (GH-105281) (cherry picked from commit 08756dbba647440803d2ba4545ba0ab2f0cdfe1c) Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* [3.12] gh-105237: Allow calling `issubclass(X, typing.Protocol)` again ↵Miss Islington (bot)2023-06-051-0/+4
| | | | | | | | (GH-105239) (#105316) gh-105237: Allow calling `issubclass(X, typing.Protocol)` again (GH-105239) (cherry picked from commit cdfb201bfa35b7c50de5099c6d9078c806851d98) Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* [3.12] gh-105144: Runtime-checkable protocols: move all 'sanity checks' to ↵Miss Islington (bot)2023-05-311-19/+15
| | | | | | | `_ProtocolMeta.__subclasscheck__` (GH-105152) (#105160) (cherry picked from commit c05c31db8c9dfd708b9857bb57f8e5f3ce40266d) Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* [3.12] gh-104943: Remove mentions of old Python versions (GH-104945) (#104963)Miss Islington (bot)2023-05-261-4/+1
| | | | | (cherry picked from commit 46857d0b2a2ac6aeb6dcce2bf2c92ddf4abe7496) Co-authored-by: Tomas R <tomas.roun8@gmail.com>
* [3.12] gh-104935: typing: Fix interactions between `@runtime_checkable` and ↵Miss Islington (bot)2023-05-251-3/+3
| | | | | | | | | | | | `Generic` (GH-104939) (#104941) gh-104935: typing: Fix interactions between `@runtime_checkable` and `Generic` (GH-104939) --------- (cherry picked from commit 2b7027d0b2ee2e102a24a0da27d01b8221f9351c) Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* [3.12] gh-104797: Allow Protocols to inherit from collections.abc.Buffer ↵Miss Islington (bot)2023-05-241-1/+1
| | | | | | | | (GH-104827) (#104841) gh-104797: Allow Protocols to inherit from collections.abc.Buffer (GH-104827) (cherry picked from commit c0ab7d401c736c37bf4462eef7c7d69fef8fab93) Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* Improve readability of `typing._ProtocolMeta.__instancecheck__` (#104649)Alex Waygood2023-05-191-13/+14
|
* gh-74690: Don't set special protocol attributes on non-protocol subclasses ↵Alex Waygood2023-05-181-6/+7
| | | | | of protocols (#104622) Don't set special protocol attributes on non-protocol subclasses of protocols
* gh-104555: Runtime-checkable protocols: Don't let previous calls to ↵Alex Waygood2023-05-171-7/+13
| | | | | `isinstance()` influence whether `issubclass()` raises an exception (#104559) Co-authored-by: Carl Meyer <carl@oddbird.net>
* typing: Use PEP 695 syntax in typing.py (#104553)Jelle Zijlstra2023-05-171-11/+17
| | | Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* gh-104555: Fix isinstance() and issubclass() for runtime-checkable protocols ↵Alex Waygood2023-05-161-1/+1
| | | | | that use PEP 695 (#104556) Fixes #104555
* gh-103763: Implement PEP 695 (#103764)Jelle Zijlstra2023-05-161-421/+170
| | | | | | | | | | | | | | This implements PEP 695, Type Parameter Syntax. It adds support for: - Generic functions (def func[T](): ...) - Generic classes (class X[T](): ...) - Type aliases (type X = ...) - New scoping when the new syntax is used within a class body - Compiler and interpreter changes to support the new syntax and scoping rules Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Co-authored-by: Eric Traut <eric@traut.com> Co-authored-by: Larry Hastings <larry@hastings.org> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* gh-91896: Revert some very noisy DeprecationWarnings for `ByteString` (#104424)Alex Waygood2023-05-131-24/+3
|
* gh-104415: Fix refleak tests for `typing.ByteString` deprecation (#104416)Nikita Sobolev2023-05-121-0/+9
|
* gh-91896: Improve visibility of `ByteString` deprecation warnings (#104294)Alex Waygood2023-05-121-1/+31
|
* gh-104392: Remove _paramspec_tvars from typing (#104393)Jelle Zijlstra2023-05-111-13/+6
| | | | This does nothing.
* gh-104328: Fix typo in ``typing.Generic`` multiple inheritance error message ↵Kirill Podoprigora2023-05-091-1/+1
| | | | (#104335)
* Improve assert_type phrasing (#104081)Shantanu2023-05-021-3/+4
| | | | | | | | | I'd like to make the fact that this does nothing at runtime really obvious, since I suspect this is unintuitive for users who are unfamiliar with static type checking. I thought of this because of https://discuss.python.org/t/add-arg-check-type-to-types/26384 wherein I'm skeptical that the user really did want `assert_type`.
* GH-103629: Update Unpack's repr in compliance with PEP 692 (#104048)Franek Magiera2023-05-011-1/+12
|
* GH-103699: Add `__orig_bases__` to various typing classes (#103698)Adrian Garcia Badaracco2023-04-231-2/+9
| | | | Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* gh-97797: Mention `__metadata__` in docstrings of `typing.{_AnnotatedAlias, ↵Nikita Sobolev2023-04-101-0/+6
| | | | | | Annotated}` (#103405) Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com> Co-authored-by: Kirill <80244920+Eclips4@users.noreply.github.com>
* gh-74690: Further optimise `typing._ProtocolMeta.__instancecheck__` (#103280)Alex Waygood2023-04-051-1/+1
|
* gh-74690: typing: Call `_get_protocol_attrs` and `_callable_members_only` at ↵Alex Waygood2023-04-051-11/+14
| | | | protocol class creation time, not during `isinstance()` checks (#103160)
* gh-74690: typing: Simplify and optimise `_ProtocolMeta.__instancecheck__` ↵Alex Waygood2023-04-051-11/+3
| | | | (#103159)
* gh-102433: Use `inspect.getattr_static` in ↵Alex Waygood2023-04-021-5/+21
| | | | `typing._ProtocolMeta.__instancecheck__` (#103034)
* gh-74690: Micro-optimise `typing._get_protocol_attrs` (#103152)Alex Waygood2023-03-311-8/+12
| | | Improve performance of `isinstance()` checks against runtime-checkable protocols
* gh-74690: typing: Don't unnecessarily call `_get_protocol_attrs` twice in ↵Alex Waygood2023-03-311-10/+21
| | | | | `_ProtocolMeta.__instancecheck__` (#103141) Speed up `isinstance()` calls against runtime-checkable protocols
* 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>