Skip to content

Commit 9d0e70f

Browse files
committed
Preserve __module__
1 parent 75c1663 commit 9d0e70f

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

Lib/warnings.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,6 @@ def __call__(self, arg, /):
597597
import functools
598598
from types import MethodType
599599

600-
wrapper_module = arg.__module__
601600
original_new = arg.__new__
602601

603602
@functools.wraps(original_new)
@@ -611,9 +610,8 @@ def __new__(cls, *args, **kwargs):
611610
raise TypeError(f"{cls.__name__}() takes no arguments")
612611
else:
613612
return original_new(cls)
614-
613+
__new__.__module__ = arg.__module__
615614
arg.__new__ = staticmethod(__new__)
616-
arg.__module__ = wrapper_module
617615

618616
original_init_subclass = arg.__init_subclass__
619617
# We need slightly different behavior if __init_subclass__
@@ -637,6 +635,7 @@ def __init_subclass__(*args, **kwargs):
637635

638636
arg.__init_subclass__ = __init_subclass__
639637

638+
__init_subclass__.__module__ = arg.__module__
640639
arg.__deprecated__ = __new__.__deprecated__ = msg
641640
__init_subclass__.__deprecated__ = msg
642641
return arg

0 commit comments

Comments
 (0)