Commit graph

367 commits

Author SHA1 Message Date
Jelle Zijlstra
3d01565da4
[3.14] gh-136316: Make typing.evaluate_forward_ref better at evaluating nested forwardrefs (GH-136319) (#136346)
Some checks are pending
Tests / (push) Blocked by required conditions
Tests / Windows MSI (push) Blocked by required conditions
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / Change detection (push) Waiting to run
Tests / Docs (push) Blocked by required conditions
Tests / Check if the ABI has changed (push) Blocked by required conditions
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
Tests / Cross build Linux (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Lint / lint (push) Waiting to run
(cherry picked from commit 9312702d2e)
2025-07-07 00:10:57 +00:00
Miss Islington (bot)
9c6d2dbe26
[3.14] gh-133960: Improve typing.evaluate_forward_ref (GH-133961) (#134663)
gh-133960: Improve typing.evaluate_forward_ref (GH-133961)

As explained in GH-133960, this removes most of the behavior differences with ForwardRef.evaluate.
The remaining difference is about recursive evaluation of forwardrefs; this is practically useful
in cases where an annotation refers to a type alias that itself is string-valued.

This also improves several edge cases that were previously not handled optimally. For example,
the function now takes advantage of the partial evaluation behavior of ForwardRef.evaluate() to
evaluate more ForwardRefs in the FORWARDREF format.

This also fixes GH-133959 as a side effect, because the buggy behavior in GH-133959 derives from
evaluate_forward_ref().
(cherry picked from commit 57fef27cfc)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2025-05-25 17:52:04 +00:00
Miss Islington (bot)
d6cb8fa86e
[3.14] gh-133701: Fix incorrect __annotations__ on TypedDict defined under PEP 563 (GH-133772) (#134003)
gh-133701: Fix incorrect `__annotations__` on TypedDict defined under PEP 563 (GH-133772)
(cherry picked from commit 9836503b48)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2025-05-14 13:54:29 +00:00
Miss Islington (bot)
89c801b84e
[3.14] gh-133925: Make typing._UnionGenericAlias hashable (GH-133929) (#133936)
gh-133925: Make typing._UnionGenericAlias hashable (GH-133929)
(cherry picked from commit 8d478c7953)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2025-05-12 15:50:10 +00:00
Jelle Zijlstra
7f16f1bc11
typing, annotationlib: clean tests (#133087)
- Add @cpython_only decorator to lazy import tests
- Rename reference to SOURCE format
- Always two newlines between test case classes
- Merge two classes of ForwardRef tests
- Use get_annotations instead of annotationlib.get_annotations
- Format test_annotationlib with Black (not expecting that we'll keep this up
  but it's close to Black-formatted right now)
2025-04-28 08:38:11 -07:00
Jelle Zijlstra
e1c09fff05
gh-132882: Fix copying of unions with members that do not support __or__ (#132883) 2025-04-24 16:49:09 +00:00
Jelle Zijlstra
5707837049
gh-132493: Avoid eager import of annotationlib in typing (again) (#132596)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2025-04-17 16:03:53 +00:00
Jelle Zijlstra
39ee468e09
gh-118761: Add helper to ensure that lazy imports are actually lazy (#132614)
This ensures that if we jump through some hoops to make sure something is imported
lazily, we don't regress on importing it.

I recently already accidentally made typing import warnings and annotationlib eagerly.

Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
2025-04-17 03:46:36 +00:00
Jelle Zijlstra
72da4a4458
typing: Add missing test case for Protocol inheritance (#132597) 2025-04-16 08:21:27 -07:00
Felix Scherz
71af090e24
gh-132493: lazy evaluation of annotations in typing._proto_hook (#132534)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: sobolevn <mail@sobolevn.me>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2025-04-16 08:20:35 -07:00
Jelle Zijlstra
7dcaebfb21
annotationlib: Move ForwardRef tests to test_annotationlib (#132571)
I started with just moving ForwardRefTests to test_annotationlib,
but found that it contained a number of tests for no_type_check, which
I moved to a new class in test_typing, as well as a number of tests that
are more appropriately classified as tests for get_type_hints().

One test, test_forward_equality_namespace(), was somewhat accidentally
depending on a global class A in test_typing. I added a class A in the
annotationlib tests instead.

Also add a useful comment in annotationlib.
2025-04-16 13:40:29 +00:00
Jelle Zijlstra
5e80fee41a
gh-129463: Remove two attributes from ForwardRef equality (#132283) 2025-04-15 12:58:21 -07:00
Jelle Zijlstra
666eeda13d
gh-132493: Support deferred annotations in Protocols (#132494) 2025-04-15 10:14:27 -07:00
Jelle Zijlstra
07b8d3117f
gh-132261: Store annotations at hidden internal keys in the class dict (#132345) 2025-04-10 21:13:26 -07:00
Jelle Zijlstra
ac14d4a23f
gh-129463, gh-128593: Simplify ForwardRef (#129465) 2025-04-05 04:36:34 +00:00
Victorien
ac3a7bfecc
Fix typo in template_replace() test helper docstring (#132094) 2025-04-04 17:38:09 +00:00
Jelle Zijlstra
5518c2ae09
gh-128661: Remove DeprecationWarning in evaluate_forward_ref (#128930)
It doesn't make sense to use a deprecation for evaluate_forward_ref,
as it is a new function in Python 3.14 and doesn't have compatibility
guarantees.

I considered making it throw an error if type_params it not passed and
there is no owner. However, I think this is too unfriendly for users. The
case where this param is really needed is fairly esoteric and I don't think
this case is worth the pain of forcing users to write "type_params=()".
2025-04-03 09:52:17 -07:00
Victorien
af2afd7c22
gh-119180: Use equality when comparing against annotationlib.Format (#131755) 2025-03-27 21:56:09 -07:00
Sebastian Rittau
c6dd2348ca
gh-127647: Add typing.Reader and Writer protocols (#127648) 2025-03-06 07:36:19 -08:00
Bartosz Sławecki
293fa3433e
gh-85795: Raise a clear error when super() is used in typing.NamedTuple subclasses (#130082) 2025-03-05 20:45:47 -08:00
Jelle Zijlstra
dc6d66f44c
gh-105499: Merge typing.Union and types.UnionType (#105511)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Ken Jin <kenjin@python.org>
Co-authored-by: Carl Meyer <carl@oddbird.net>
2025-03-04 11:44:19 -08:00
Daraan
d8ce092fe4
Add test checking value of a TypedDict's __total__ attribute when there is an assignment in the class body. (#130460)
In relation to #109544 which changed this behavior.

Signed-off-by: Daniel Sperber <github.blurry@9ox.net>
2025-02-22 09:34:22 -08:00
Serhiy Storchaka
859db49029
gh-71339: Use new assertion methods in test_typing (GH-128825) 2025-01-14 15:19:32 +02:00
Serhiy Storchaka
06cad77a5b
gh-71339: Add additional assertion methods for unittest (GH-128707)
Add the following methods:

* assertHasAttr() and assertNotHasAttr()
* assertIsSubclass() and assertNotIsSubclass()
* assertStartsWith() and assertNotStartsWith()
* assertEndsWith() and assertNotEndsWith()

Also improve error messages for assertIsInstance() and
assertNotIsInstance().
2025-01-14 10:02:38 +02:00
sobolevn
b725297cee
gh-128661: Fix typing.evaluate_forward_ref not showing deprecation (#128663)
gh-128661: Fix `typing.evaluate_forward_ref` not showing deprecataion
2025-01-09 18:15:13 +03:00
sobolevn
43ac9f5059
gh-128673: Increase coverage of typing.get_type_hints (#128674) 2025-01-09 17:25:03 +03:00
sobolevn
74a517181a
gh-128615: Cover pickling of ParamSpecArgs and ParamSpecKwargs (#128616) 2025-01-08 15:04:54 +03:00
sobolevn
eb26e17069
gh-128613: Increase typing.Concatenate coverage (#128614) 2025-01-08 15:02:47 +03:00
sobolevn
971a52b549
gh-128617: Fix test_typing.test_readonly_inheritance (#128618) 2025-01-08 14:19:41 +03:00
Serhiy Storchaka
b2ac70a62a
gh-88834: Unify the instance check for typing.Union and types.UnionType (GH-128363)
Union now uses the instance checks against its parameters instead of
the subclass checks.
2024-12-31 10:02:58 +02:00
Stephen Morton
a83472f49b
gh-126705: Make os.PathLike more like a protocol (#126706)
it can now be used as a base class in other protocols
2024-11-12 17:54:13 +00:00
Stephen Morton
feb3e0b19c
gh-126699: allow AsyncIterator to be used as a base for Protocols (#126702) 2024-11-12 09:17:07 +00:00
Jelle Zijlstra
2c10832887
gh-119180: Rename SOURCE format to STRING (#124620) 2024-09-26 13:49:48 -07:00
Jelle Zijlstra
96f619faa7
gh-124206: Fix calling get_annotate_function() on static types (#124208)
Fixes #124206. No news entry because the bug this fixes was never
released.
2024-09-18 08:39:22 -07:00
Wulian
94036e43a8
Fix typos in comments (#123201) 2024-08-21 12:49:23 +00:00
Kirill Podoprigora
2037d8cbae
gh-122835: Fix module name in `test_typing` (#122836) 2024-08-08 19:26:31 +00:00
Serhiy Storchaka
540fcc62f5
gh-118814: Fix the TypeVar constructor when name is passed by keyword (GH-122664)
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.
2024-08-07 23:30:10 +03:00
Jelle Zijlstra
7b7b90d1ce
gh-119180: Add annotationlib module to support PEP 649 (#119891)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2024-07-23 21:16:50 +00:00
Alex Waygood
2d3187bf20
gh-114053: Fix another edge case involving get_type_hints, PEP 695 and PEP 563 (#120272) 2024-06-25 16:53:18 +01:00
Jelle Zijlstra
9b8611eeea
gh-119180: PEP 649 compiler changes (#119361) 2024-06-11 13:06:49 +00:00
Jelle Zijlstra
e9875ecb5d
gh-119180: PEP 649: Add __annotate__ attributes (#119209) 2024-05-22 04:38:12 +02:00
Alex Waygood
a9328e2b6e
typing tests: remove some unnecessary uses of exec() (#119005) 2024-05-14 07:16:14 -07:00
Jelle Zijlstra
ec9d12be96
Rename typing._collect_parameters (#118900)
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.
2024-05-10 16:55:49 +00:00
Jelle Zijlstra
13d7cf997b
gh-118895: Call PyType_Ready() on typing.NoDefault (#118897) 2024-05-10 08:42:00 -07:00
Nikita Sobolev
2f4db5a04d
gh-118803: Remove ByteString from typing and collections.abc (#118804) 2024-05-09 00:37:55 +01:00
Jelle Zijlstra
aac6b019fe
gh-118772: Allow TypeVars without a default to follow those with a default when constructing aliases (#118774) 2024-05-08 09:54:51 -07:00
Jelle Zijlstra
71080b8a0f
gh-118660: Add second type parameter to (Async)ContextManager (#118681)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2024-05-07 14:16:05 +00:00
Alex Waygood
0f8a07d158
gh-118418: Deprecate failing to pass a value to the *type_params* parameter of some private typing APIs (#118695) 2024-05-07 11:12:28 +00:00
Jelle Zijlstra
8419f01673
gh-118647: Add defaults to typing.Generator and typing.AsyncGenerator (#118648)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2024-05-06 22:35:06 +00:00
Jelle Zijlstra
ca269e58c2
gh-116126: Implement PEP 696 (#116129)
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>
2024-05-03 06:17:32 -07:00