From 634ce9016a1852bdeee7f88089eee114630546e0 Mon Sep 17 00:00:00 2001 From: Joshua Cannon <3956745+thejcannon@users.noreply.github.com> Date: Sun, 9 Feb 2025 20:14:43 -0600 Subject: [PATCH 1/2] use functools.wraps within overloads --- Lib/test/test_typing.py | 20 ++++++++++++++++++++ Lib/typing.py | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index f002d28df60e9c..f289e20a0ccd5c 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -6646,6 +6646,26 @@ def test_overload_registry_repeated(self): self.assertEqual(list(get_overloads(impl)), overloads) + def test_overload_wraps(self): + @overload + def norwegian_blue(x: "int"): + """pining for the fjords""" + + self.assertEqual(norwegian_blue.__doc__, "pining for the fjords") + self.assertEqual(norwegian_blue.__name__, "norwegian_blue") + self.assertEqual(norwegian_blue.__annotations__, {"x": int}) + + # But also make sure this isn't the same function each time + setattr(norwegian_blue, "sentinel", object()) + + @overload + def ex_parrot(): + """ceased to be""" + + self.assertFalse(hasattr(ex_parrot, "sentinel")) + self.assertEqual(ex_parrot.__doc__, "ceased to be") + self.assertEqual(norwegian_blue.__doc__, "pining for the fjords") + from test.typinganndata import ( ann_module, ann_module2, ann_module3, ann_module5, ann_module6, diff --git a/Lib/typing.py b/Lib/typing.py index 66570db7a5bd74..79b8edf3a47463 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -2687,7 +2687,7 @@ def utf8(value): except AttributeError: # Not a normal function; ignore. pass - return _overload_dummy + return functools.wraps(func)(lambda *args, **kwds: _overload_dummy(*args, **kwds)) def get_overloads(func): From 7aaaa33c39208545783fa477ffd4190f4a909acf Mon Sep 17 00:00:00 2001 From: Joshua Cannon <3956745+thejcannon@users.noreply.github.com> Date: Sun, 9 Feb 2025 20:45:56 -0600 Subject: [PATCH 2/2] oops thats a string --- Lib/test/test_typing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index f289e20a0ccd5c..8dfe4d24612e21 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -6653,7 +6653,7 @@ def norwegian_blue(x: "int"): self.assertEqual(norwegian_blue.__doc__, "pining for the fjords") self.assertEqual(norwegian_blue.__name__, "norwegian_blue") - self.assertEqual(norwegian_blue.__annotations__, {"x": int}) + self.assertEqual(norwegian_blue.__annotations__, {"x": "int"}) # But also make sure this isn't the same function each time setattr(norwegian_blue, "sentinel", object())