Commit graph

302 commits

Author SHA1 Message Date
Miss Islington (bot)
d8890fb82d
[3.12] gh-128613: Increase typing.Concatenate coverage (GH-128614) (#128624)
gh-128613: Increase `typing.Concatenate` coverage (GH-128614)
(cherry picked from commit eb26e17069)

Co-authored-by: sobolevn <mail@sobolevn.me>
2025-01-08 12:20:00 +00:00
Miss Islington (bot)
ca017a171a
[3.12] gh-88834: Unify the instance check for typing.Union and types.UnionType (GH-128363) (GH-128371)
Union now uses the instance checks against its parameters instead of
the subclass checks.
(cherry picked from commit b2ac70a62a)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-12-31 08:19:45 +00:00
Miss Islington (bot)
34137cbd23
[3.12] gh-126699: allow AsyncIterator to be used as a base for Protocols (GH-126702) (#126761)
gh-126699: allow AsyncIterator to be used as a base for Protocols (GH-126702)
(cherry picked from commit feb3e0b19c)

Co-authored-by: Stephen Morton <github@tungol.org>
2024-12-02 14:18:53 +00:00
Serhiy Storchaka
f2cc8ad989
[3.12] gh-118814: Fix the TypeVar constructor when name is passed by keyword (GH-122664) (GH-122807)
Fix _PyArg_UnpackKeywordsWithVararg for the case when argument for
positional-or-keyword parameter is passed by keyword.
There was only one such case in the stdlib -- the TypeVar constructor.
(cherry picked from commit 540fcc62f5)
2024-08-08 09:49:50 +03:00
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)
4695f1a364
[3.12] typing tests: remove some unnecessary uses of exec() (GH-119005) (#119039)
(cherry picked from commit a9328e2b6e)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2024-05-14 14:51:08 +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)
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
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
Nikita Sobolev
919be35eae
[3.12] gh-112155: Run typing.py doctests during tests (GH-112156) (#112230) 2023-11-18 11:13:37 +00:00
Alex Waygood
9aa5ff82d4
[3.12] gh-111681: minor fixes to typing doctests; remove unused imports in test_typing (#111682) (#112035)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2023-11-13 14:08:57 +00:00
Nikita Sobolev
992c3f6b51
[3.12] gh-108303: Move more typing related files to Lib/test/typinganndata (GH-111825) (#111859)
[3.12] gh-108303: Move more typing related files to Lib/test/typinganndata(GH-111825)
2023-11-08 16:56:24 +00:00
Miss Islington (bot)
4a1026077a
[3.12] gh-111126: Use isinstance instead of assert[Not]IsInstance in test_typing (GH-111127) (#111130)
gh-111126: Use `isinstance` instead of `assert[Not]IsInstance` in `test_typing` (GH-111127)
(cherry picked from commit ea7c26e4b8)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2023-10-20 18:27:35 +00:00
Miss Islington (bot)
27d5ea291c
[3.12] gh-110782: Fix crash when TypeVar is constructed with keyword args (GH-110784) (#110787)
gh-110782: Fix crash when TypeVar is constructed with keyword args (GH-110784)
(cherry picked from commit d2a536b170)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2023-10-12 23:24:37 +00:00
Alex Waygood
4dac406f66
[3.12] Enable ruff on Lib/test/test_typing.py (#110179) (#110288)
Enable ruff on `Lib/test/test_typing.py` (#110179)
2023-10-03 15:13:22 +00:00
Miss Islington (bot)
46e69576a9
[3.12] gh-110178: Use fewer weakrefs in test_typing.py (GH-110194) (#110224)
gh-110178: Use fewer weakrefs in test_typing.py (GH-110194)

Confirmed that without the C changes from GH-108517, this test still segfaults with only 10 weakrefs.
(cherry picked from commit 732ad44cec)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2023-10-02 18:15:30 +01:00
Miss Islington (bot)
b153cab6d8
[3.12] gh-108303: Move ann_module*.py files to typinganndata/ folder (GH-108354) (#109672)
gh-108303: Move `ann_module*.py` files to `typinganndata/` folder (GH-108354)
(cherry picked from commit 3f61cf646d)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2023-10-02 17:10:33 +02:00
Miss Islington (bot)
09877a15d5
[3.12] gh-108295: Fix crashes with TypeVar weakrefs (GH-108517) (#108527)
gh-108295: Fix crashes with TypeVar weakrefs (GH-108517)
(cherry picked from commit 482fad7f01)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2023-08-27 16:12:57 +02: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)
e6982c5860
[3.12] gh-105834: Add tests for calling issubclass() between two protocols (GH-105835) (#105859)
Some parts of the implementation of `typing.Protocol` had poor test coverage
(cherry picked from commit 70c075c194)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-06-16 16:20:19 +00:00
Miss Islington (bot)
2b6f475db8
[3.12] gh-105431: Remove unused stuff from test_typing.NewTypeTests (GH-105432) (#105489)
gh-105431: Remove unused stuff from `test_typing.NewTypeTests` (GH-105432)
(cherry picked from commit 9d35a71a76)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2023-06-08 06:57:21 +00:00
Miss Islington (bot)
4b2263e4bf
[3.12] gh-103171: Forward-port new tests for runtime-checkable protocols decorated with @final (GH-105473) (#105474)
Forward-port of the tests that were added to the 3.11 branch in GH-105445
(cherry picked from commit f5df347fcf)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-06-07 22:54:42 +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)
01af2b0e51
[3.12] Remove raw asserts in test_typing.py (GH-104951) (#104978)
Remove raw asserts in test_typing.py (GH-104951)
(cherry picked from commit 2cb445635e)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2023-05-26 14:35:35 +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)
b670214636
[3.12] gh-104879: Fix TypeAliasType.__module__ in exec() (GH-104881) (#104890)
(cherry picked from commit fe77a99fc8)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2023-05-24 19:30:57 +00:00
Miss Islington (bot)
3d91d034a0
[3.12] Improve test coverage for is_typeddict (GH-104884) (#104889)
Improve test coverage for is_typeddict (GH-104884)

In particular, it's important to test that is_typeddict(TypedDict)
returns False.
(cherry picked from commit 1497607a8e)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2023-05-24 19:21:28 +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
b870b1fa75
gh-74690: Make a typing test more resilient (#104691) 2023-05-20 17:13:37 -07:00
Jelle Zijlstra
8f1f3b9abd
gh-104600: Make type.__type_params__ writable (#104634)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-05-19 09:04:47 -07: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
26931944dd
typing: Add more tests for TypeVar (#104571)
During the PEP 695 implementation at one point I made
TypeVar.__name__ return garbage, and all of test_typing passed.
So I decided to add a few more tests. In the process I discovered
a minor incompatibility from the C implementation of TypeVar:
empty constraints were returned as None instead of an empty tuple.
2023-05-17 06:08:21 -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
Alex Waygood
f0f5bb3204
gh-91896: Improve visibility of ByteString deprecation warnings (#104294) 2023-05-11 23:01:31 -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
Kirill Podoprigora
4181d078fc
gh-104036: Fix direct invocation of test_typing (#104037)
Previously, `python -m test test_typing` worked, but `python Lib/test/test_typing.py` did not.
2023-05-01 13:42:59 +00:00
Nikita Sobolev
3d29edaf0a
gh-103746: Test types.UnionType and Literal types together (#103747) 2023-04-24 10:55:16 -06:00
Nikita Sobolev
5041c2ba6e
gh-103592: Add tests of Literal with Enum and Union of Literals (#103706) 2023-04-23 11:50:23 -06:00