Commit Graph

29 Commits

Author SHA1 Message Date
Jelle Zijlstra 3e562b3942
gh-133684: Fix get_annotations() where PEP 563 is involved (#133795) 2025-05-25 08:40:58 -07:00
Jelle Zijlstra 90f476e0f8
gh-133551: Support t-strings in annotationlib (#133553)
I don't know why you'd use t-strings in annotations, but now if you do,
the STRING format will do a great job of recovering the source code.
2025-05-07 18:10:35 -07:00
Jelle Zijlstra 4e498d1e8b
gh-119180: Make the FORWARDREF format work with more kinds of runtime errors (#133407) 2025-05-05 08:21:11 -07:00
Jelle Zijlstra af5799f305
gh-125618: Make FORWARDREF format succeed more often (#132818)
Fixes #125618.
2025-05-04 15:21:56 -07:00
Jelle Zijlstra c8f233c53b
gh-132805: annotationlib: Fix handling of non-constant values in FORWARDREF (#132812)
Co-authored-by: David C Ellis <ducksual@gmail.com>
2025-05-04 08:49:13 -07:00
Jelle Zijlstra 7cb86c5def
gh-132426: Add get_annotate_from_class_namespace replacing get_annotate_function (#132490)
As noted on the issue, making get_annotate_function() support both types and
mappings is problematic because one object may be both. So let's add a new one
that works with any mapping.

This leaves get_annotate_function() not very useful, so remove it.
2025-05-04 07:26:42 -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 a8ca26d250
annotationlib: Remove some unnecessary dict copies (#132495) 2025-04-16 06:16:13 -07:00
Jelle Zijlstra 11f6603845
gh-132491: Rename annotationlib.value_to_string to type_repr (#132492) 2025-04-15 20:10:53 +00:00
Jelle Zijlstra 5e80fee41a
gh-129463: Remove two attributes from ForwardRef equality (#132283) 2025-04-15 12:58:21 -07:00
Jelle Zijlstra 4d3ad0467e
gh-132064: Make annotationlib use __annotate__ if only it is present (#132195) 2025-04-13 16:32:44 -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
Jelle Zijlstra 255eb375a7
gh-118761: Defer import of functools in annotationlib (#132059) 2025-04-04 06:42:22 -07:00
Adam Turner b3e3cc054c
Remove deferred ``typing`` import in ``annotationlib`` (#132034) 2025-04-02 20:30:31 -07:00
Jelle Zijlstra dcf629213b
gh-119180: Add VALUE_WITH_FAKE_GLOBALS format to annotationlib (#124415) 2024-11-26 15:40:13 +00:00
Jelle Zijlstra d3be6f945a
gh-125614: annotationlib: Fix bug where not all Stringifiers are converted (#125635) 2024-10-23 16:27:55 -07:00
larryhastings 626d706a66
Minor edit for code clarification in annotationlib. (#124805) 2024-09-30 15:25:56 -07:00
Jelle Zijlstra 2c10832887
gh-119180: Rename SOURCE format to STRING (#124620) 2024-09-26 13:49:48 -07:00
Jelle Zijlstra 4e829c0e6f
gh-124412: Add helpers for converting annotations to source format (#124551) 2024-09-26 00:01:09 +00:00
Jelle Zijlstra bc543936ab
gh-119180: Make FORWARDREF format look at __annotations__ first (#124479)
From discussion with Larry Hastings and Carl Meyer, this is the desired
behavior.
2024-09-25 15:32:45 -07:00
Jelle Zijlstra 17a544b257
gh-119180: Avoid going through AST and eval() when possible in annotationlib (#124337)
Often, ForwardRefs represent a single simple name. In that case, we
can avoid going through the overhead of creating AST nodes and code
objects and calling eval(): we can simply look up the name directly
in the relevant namespaces.

Co-authored-by: Victor Stinner <vstinner@python.org>
2024-09-25 21:14:03 +00:00
Jelle Zijlstra 2e0d445364
gh-119180: Fix annotationlib.ForwardRef.evaluate with no globals (#124326)
We were sometimes passing None as the globals argument to eval(), which makes it
inherit the globals from the calling scope. Instead, ensure that globals is always
non-None. The test was passing accidentally because I passed "annotationlib" as a
module object; fix that. Also document the parameters to ForwardRef() and remove
two unused private ones.

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2024-09-23 19:06:19 +00: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
Jelle Zijlstra 4534068f22
gh-119180: annotationlib: Fix __all__, formatting (#122365) 2024-08-11 23:44:51 +00:00
Jelle Zijlstra 016f4b5975
gh-119180: Improvements to ForwardRef.evaluate (#122210)
Noticed some issues while writing documentation for this method.
2024-08-11 23:42:57 +00:00
Jelle Zijlstra ae192262ad
gh-119180: Add evaluate functions for type params and type aliases (#122212) 2024-07-27 17:24:10 +00:00
Jelle Zijlstra 45614ecb2b
gh-119180: Use type descriptors to access annotations (PEP 749) (#122074) 2024-07-27 16:36:06 +00: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