From e7a270a1db4752c5e9ae8d4106eae32d8f9b2138 Mon Sep 17 00:00:00 2001 From: dr-carlos <77367421+dr-carlos@users.noreply.github.com> Date: Thu, 13 Aug 2026 23:47:21 +0930 Subject: [PATCH] gh-141174: Test `get_annotations()` on wrapped cyclical `functools.partial` (GH-155663) Test `get_annotations()` on wrapped cyclical `functools.partial` (cherry picked from commit 5d3f02a5c339f03fc377bacd40a83eb9217ffddb) Co-authored-by: dr-carlos <77367421+dr-carlos@users.noreply.github.com> --- Lib/test/test_annotationlib.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Lib/test/test_annotationlib.py b/Lib/test/test_annotationlib.py index 5087c3ca425f1fc..b86b94d5b5c87dd 100644 --- a/Lib/test/test_annotationlib.py +++ b/Lib/test/test_annotationlib.py @@ -654,6 +654,13 @@ def f(x: 'int') -> 'str': ... result = get_annotations(f, eval_str=True) self.assertEqual(result, {'x': int, 'return': str}) + def test_eval_str_wrapped_partial_cycle_self(self): + def f(x: 'int') -> 'str': ... + f.__wrapped__ = functools.partial(f, 0) + # Cycle is detected and broken; globals from f itself are used. + result = get_annotations(f, eval_str=True) + self.assertEqual(result, {'x': int, 'return': str}) + def test_eval_str_wrapped_cycle_mutual(self): # gh-146556: mutual __wrapped__ cycle (a -> b -> a) must not hang. def a(x: 'int'): ...