Commit graph

292 commits

Author SHA1 Message Date
Miss Islington (bot)
a85241d76b
[3.12] gh-114053: Fix another edge case involving get_type_hints, PEP 695 and PEP 563 (GH-120272) (#121004)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2024-06-25 16:31:01 +00:00
Miss Islington (bot)
0586d54241
[3.12] gh-118418: Use a default value for type_params in typing._eval_type (GH-118431) (#118436)
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2024-04-30 16:26:38 +00:00
Miss Islington (bot)
30e25d4ff9
[3.12] gh-118168: Fix Unpack interaction with builtin aliases (GH-118169) (#118178)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2024-04-23 13:57:36 +00:00
Alex Waygood
5430f61437
[3.12] gh-114053: Fix bad interaction of PEP-695, PEP-563 and `get_type_hints` (#118009) (#118104)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-04-19 13:41:28 +00:00
Miss Islington (bot)
b5e12aa9ff
[3.12] gh-117521: Improve typing.TypeGuard docstring (GH-117522) (#117538)
(cherry picked from commit b32789ccb9)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-04-04 11:04:16 +00:00
Miss Islington (bot)
9f831f442c
[3.12] gh-117110: Fix subclasses of typing.Any with custom constructors (GH-117111) (#117357)
gh-117110: Fix subclasses of typing.Any with custom constructors (GH-117111)
(cherry picked from commit 8eec7ed714)

Co-authored-by: 傅立业(Chris Fu) <17433201@qq.com>
2024-03-29 00:36:14 +00:00
Miss Islington (bot)
6264c4f4b2
[3.12] gh-116325: Raise SyntaxError rather than IndexError on ForwardRef 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 a29998a06b)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2024-03-05 10:08:27 +00:00
Miss Islington (bot)
90f75e1069
[3.12] gh-112281: Allow Union with unhashable Annotated metadata (GH-112283) (#116213)
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2024-03-01 18:01:27 +00:00
Jelle Zijlstra
83c7dd5200
[3.12] gh-115570: Fix DeprecationWarnings in test_typing (#115571) (#115574)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2024-02-16 13:46:48 -08:00
Miss Islington (bot)
321ec5e0fe
[3.12] gh-115165: Fix typing.Annotated for immutable types (GH-115213) (#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 564385612c)

Co-authored-by: dave-shawley <daveshawley@gmail.com>
2024-02-09 22:31:57 +00:00
Alex Waygood
8435fbfe4e
[3.12] gh-113320: Reduce the number of dangerous getattr() calls when 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)
2024-01-05 01:51:17 +00:00
Miss Islington (bot)
b01caf1d9d
[3.12] gh-113255: Clarify docs for typing.reveal_type (GH-113286) (#113323)
gh-113255: Clarify docs for `typing.reveal_type` (GH-113286)
(cherry picked from commit 11ee912327)

Co-authored-by: Kir <note351@hotmail.com>
Co-authored-by: AlexWaygood <alex.waygood@gmail.com>
2023-12-20 17:36:45 +00:00
Alex Waygood
2a378ca2ef
[3.12] gh-112618: Make Annotated cache typed (#112619) (#112628) 2023-12-03 00:41:03 +00:00
Miss Islington (bot)
c67812668f
[3.12] gh-112509: Fix keys being present in both required_keys and optional_keys in TypedDict (GH-112512) (#112530)
(cherry picked from commit 4038869423)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-11-29 17:55:06 +00:00
Miss Islington (bot)
0ea645445d
[3.12] gh-112194: Convert more examples to doctests in typing.py (GH-112195) (#112208)
gh-112194: Convert more examples to doctests in `typing.py` (GH-112195)
(cherry picked from commit 949b2cc6ea)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-11-17 18:28:35 +00:00
Miss Islington (bot)
458a3c02e5
[3.12] GH-112152: Fix typo in typing.override docstring (GH-112158) (#112162)
GH-112152: Fix typo in `typing.override` docstring (GH-112158)
(cherry picked from commit 12c7e9d573)

Co-authored-by: Qua27 <92877777+Qua27@users.noreply.github.com>
2023-11-16 15:32:47 +00:00
Miss Islington (bot)
7d6ee298e9
[3.12] gh-105974: Revert unintentional behaviour change for protocols with 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 9499b0f138)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-06-23 15:26:37 +00:00
Miss Islington (bot)
7c298d2dc5
[3.12] Miscellaneous improvements to the typing docs (GH-105529) (#105567)
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 8e755923c9)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-06-09 15:37:33 +00:00
Miss Islington (bot)
3c5f0eadd8
[3.12] Further improve docs for typing.Annotated (GH-105498) (#105503)
Further improve docs for `typing.Annotated` (GH-105498)
(cherry picked from commit d213c2990f)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-06-08 15:12:35 +00:00
Miss Islington (bot)
9a7c4a5f39
[3.12] typing: Improve documentation of generic classes and aliases (GH-105369) (#105453)
typing: Improve documentation of generic classes and aliases (GH-105369)
(cherry picked from commit d63a7c3694)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-06-07 15:04:14 +00:00
Miss Islington (bot)
98ccc2de6b
[3.12] gh-105430: Remove typing._Immutable unused internal helper (GH-105434) (#105451)
gh-105430: Remove `typing._Immutable` unused internal helper (GH-105434)
(cherry picked from commit 18309ad94b)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2023-06-07 14:30:39 +00:00
Miss Islington (bot)
84133c56f3
[3.12] gh-105286: Further improvements to typing.py docstrings (GH-105363) (#105416)
gh-105286: Further improvements to `typing.py` docstrings (GH-105363)
(cherry picked from commit 9a89f1bf1e)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-06-07 00:51:16 +00:00
Alex Waygood
83fc562ea5
[3.12] gh-105286: Improve typing.py docstrings (#105287) (#105319)
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>
2023-06-05 15:05:21 +00:00
Miss Islington (bot)
2031238eb6
[3.12] gh-105280: Ensure isinstance([], collections.abc.Mapping) always evaluates to False (GH-105281) (#105318)
gh-105280: Ensure `isinstance([], collections.abc.Mapping)` always evaluates to `False` (GH-105281)
(cherry picked from commit 08756dbba6)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-06-05 14:51:26 +00:00
Miss Islington (bot)
51750269cf
[3.12] gh-105237: Allow calling issubclass(X, typing.Protocol) again (GH-105239) (#105316)
gh-105237: Allow calling `issubclass(X, typing.Protocol)` again (GH-105239)
(cherry picked from commit cdfb201bfa)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-06-05 14:06:25 +00:00
Miss Islington (bot)
076f3cda14
[3.12] gh-105144: Runtime-checkable protocols: move all 'sanity checks' to _ProtocolMeta.__subclasscheck__ (GH-105152) (#105160)
(cherry picked from commit c05c31db8c)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-05-31 17:35:03 +00:00
Miss Islington (bot)
6324458bef
[3.12] gh-104943: Remove mentions of old Python versions (GH-104945) (#104963)
(cherry picked from commit 46857d0b2a)

Co-authored-by: Tomas R <tomas.roun8@gmail.com>
2023-05-26 07:15:56 +00:00
Miss Islington (bot)
930efde4c7
[3.12] gh-104935: typing: Fix interactions between @runtime_checkable and Generic (GH-104939) (#104941)
gh-104935: typing: Fix interactions between `@runtime_checkable` and `Generic` (GH-104939)

---------

(cherry picked from commit 2b7027d0b2)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-05-25 17:15:48 +00:00
Miss Islington (bot)
d10d1e3b10
[3.12] gh-104797: Allow Protocols to inherit from collections.abc.Buffer (GH-104827) (#104841)
gh-104797: Allow Protocols to inherit from collections.abc.Buffer (GH-104827)
(cherry picked from commit c0ab7d401c)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2023-05-24 09:05:34 +00:00
Alex Waygood
a412fc58cc
Improve readability of typing._ProtocolMeta.__instancecheck__ (#104649) 2023-05-19 14:30:02 +01:00
Alex Waygood
f7835fc7e9
gh-74690: Don't set special protocol attributes on non-protocol subclasses of protocols (#104622)
Don't set special protocol attributes on non-protocol subclasses of protocols
2023-05-19 00:34:40 +01:00
Alex Waygood
b27fe67f3c
gh-104555: Runtime-checkable protocols: Don't let previous calls to isinstance() influence whether issubclass() raises an exception (#104559)
Co-authored-by: Carl Meyer <carl@oddbird.net>
2023-05-17 23:43:12 +00:00
Jelle Zijlstra
0cb2fdc621
typing: Use PEP 695 syntax in typing.py (#104553)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-05-17 06:03:58 -07:00
Alex Waygood
1163782868
gh-104555: Fix isinstance() and issubclass() for runtime-checkable protocols that use PEP 695 (#104556)
Fixes #104555
2023-05-16 16:38:10 +00:00
Jelle Zijlstra
24d8b88420
gh-103763: Implement PEP 695 (#103764)
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>
2023-05-15 20:36:23 -07:00
Alex Waygood
c527eb1c2a
gh-91896: Revert some very noisy DeprecationWarnings for ByteString (#104424) 2023-05-13 09:55:35 +01:00
Nikita Sobolev
5b8cd5abe5
gh-104415: Fix refleak tests for typing.ByteString deprecation (#104416) 2023-05-12 05:36:12 -07:00
Alex Waygood
f0f5bb3204
gh-91896: Improve visibility of ByteString deprecation warnings (#104294) 2023-05-11 23:01:31 -07:00
Jelle Zijlstra
37a5d256b9
gh-104392: Remove _paramspec_tvars from typing (#104393)
This does nothing.
2023-05-11 16:41:26 -07:00
Kirill Podoprigora
01c321ca34
gh-104328: Fix typo in `typing.Generic` multiple inheritance error message (#104335) 2023-05-09 13:18:15 -06:00
Shantanu
82ba6ce303
Improve assert_type phrasing (#104081)
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`.
2023-05-01 23:05:25 -07:00
Franek Magiera
2d526cd32f
GH-103629: Update Unpack's repr in compliance with PEP 692 (#104048) 2023-05-01 17:58:50 +00:00
Adrian Garcia Badaracco
0056701aa3
GH-103699: Add __orig_bases__ to various typing classes (#103698)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2023-04-23 08:33:39 -06:00
Nikita Sobolev
dc604a8c58
gh-97797: Mention __metadata__ in docstrings of typing.{_AnnotatedAlias, Annotated} (#103405)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Kirill <80244920+Eclips4@users.noreply.github.com>
2023-04-10 15:57:17 +01:00
Alex Waygood
de18267685
gh-74690: Further optimise typing._ProtocolMeta.__instancecheck__ (#103280) 2023-04-05 17:37:36 +01:00
Alex Waygood
3246688918
gh-74690: typing: Call _get_protocol_attrs and _callable_members_only at protocol class creation time, not during isinstance() checks (#103160) 2023-04-05 12:19:03 +01:00
Alex Waygood
47753ecde2
gh-74690: typing: Simplify and optimise _ProtocolMeta.__instancecheck__ (#103159) 2023-04-05 10:07:30 +01:00
Alex Waygood
6d59c9e32e
gh-102433: Use inspect.getattr_static in typing._ProtocolMeta.__instancecheck__ (#103034) 2023-04-02 14:22:19 +01:00
Alex Waygood
361a3eaf1b
gh-74690: Micro-optimise typing._get_protocol_attrs (#103152)
Improve performance of `isinstance()` checks against runtime-checkable protocols
2023-03-31 21:54:50 +01:00
Alex Waygood
9048d73f7a
gh-74690: typing: Don't unnecessarily call _get_protocol_attrs twice in _ProtocolMeta.__instancecheck__ (#103141)
Speed up `isinstance()` calls against runtime-checkable protocols
2023-03-31 18:37:24 +01:00