Repository navigation
Preserve function metadata and annotation callback lifetimes #9162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -310,7 +310,7 @@ def check_annotations(self, f): | |
| print(f.__annotations__) | ||
|
|
||
| f.__annotate__ = lambda x: 42 | ||
| with self.assertRaisesRegex(TypeError, r"__annotate__ returned non-dict of type 'int'"): | ||
| with self.assertRaisesRegex(TypeError, r"__annotate__\(\) must return a dict, not int"): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For changes under AGENTS.md reference: AGENTS.md:L278-L282 Useful? React with 👍 / 👎. |
||
| print(f.__annotations__) | ||
|
|
||
| f.__annotate__ = lambda x: {"x": x} | ||
|
|
@@ -783,21 +783,6 @@ def test_non_name_annotations(self): | |
|
|
||
|
|
||
| class RegressionTests(unittest.TestCase): | ||
| # gh-154902 | ||
| def test_conditional_annotations_rebound(self): | ||
| # user code can rebind __conditional_annotations__ to any object | ||
| lefts = ("__conditional_annotations__", | ||
| 'globals()["__conditional_annotations__"]') | ||
| values = ("0", "{}", "[]", "''", "object()", "frozenset()") | ||
| for left, value in itertools.product(lefts, values): | ||
| with self.subTest(left=left, value=value): | ||
| code = f""" | ||
| {left} = {value} | ||
| x: int | ||
| """ | ||
| with self.assertRaises(TypeError): | ||
| run_code(code) | ||
|
|
||
| # gh-132479 | ||
| def test_complex_comprehension_inlining(self): | ||
| # Test that the various repro cases from the issue don't crash | ||
|
|
@@ -871,9 +856,9 @@ def method(self, x: int): | |
| """ | ||
| ns = run_code(code) | ||
| method = ns["Outer"].method | ||
| self.assertEqual(method.__annotate__.__qualname__, "Outer.method.__annotate__") | ||
| self.assertEqual(ns["f"].__annotate__.__qualname__, "f.__annotate__") | ||
| self.assertEqual(ns["f"]().__annotate__.__qualname__, "f.<locals>.nested.__annotate__") | ||
| self.assertEqual(method.__annotate__.__qualname__, "Outer.method.__annotate__") | ||
| self.assertEqual(ns["Outer"].__annotate__.__qualname__, "Outer.__annotate__") | ||
|
|
||
| # gh-138349 | ||
|
|
@@ -912,3 +897,18 @@ class Generic: | |
| mod = build_module(code) | ||
| annos = mod.__annotations__ | ||
| self.assertEqual(annos, {"annotated_name": 0}) | ||
|
|
||
| # gh-154902 | ||
| def test_conditional_annotations_rebound(self): | ||
| # user code can rebind __conditional_annotations__ to any object | ||
| lefts = ("__conditional_annotations__", | ||
| 'globals()["__conditional_annotations__"]') | ||
| values = ("0", "{}", "[]", "''", "object()", "frozenset()") | ||
| for left, value in itertools.product(lefts, values): | ||
| with self.subTest(left=left, value=value): | ||
| code = f""" | ||
| {left} = {value} | ||
| x: int | ||
| """ | ||
| with self.assertRaises(TypeError): | ||
| run_code(code) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For changes under
Lib/test, addingfrozendictandslicetogeneric_typeschanges the test data, while repository policy allows only expected-failure decorator edits. Revert this migrated type-list change rather than modifying the test inputs.AGENTS.md reference: AGENTS.md:L278-L282
Useful? React with 👍 / 👎.