summaryrefslogtreecommitdiffstats
path: root/Lib/inspect.py
diff options
context:
space:
mode:
authorTian Gao <gaogaotiantian@hotmail.com>2023-06-02 22:22:33 (GMT)
committerGitHub <noreply@github.com>2023-06-02 22:22:33 (GMT)
commit9ad199ba36791711f596393ca9a20dbf118ef858 (patch)
treef807ee7ccf7d68fe97f9c4a8d3b66bccae1c6071 /Lib/inspect.py
parent70dc2fb9732ba3848ad3ae511a9d3195b1378915 (diff)
downloadcpython-9ad199ba36791711f596393ca9a20dbf118ef858.zip
cpython-9ad199ba36791711f596393ca9a20dbf118ef858.tar.gz
cpython-9ad199ba36791711f596393ca9a20dbf118ef858.tar.bz2
gh-105080: Fixed inconsistent signature on derived classes (#105217)
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r--Lib/inspect.py23
1 files changed, 12 insertions, 11 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index 15eefdb..a550202 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -2581,17 +2581,18 @@ def _signature_from_callable(obj, *,
factory_method = None
new = _signature_get_user_defined_method(obj, '__new__')
init = _signature_get_user_defined_method(obj, '__init__')
- # Now we check if the 'obj' class has an own '__new__' method
- if '__new__' in obj.__dict__:
- factory_method = new
- # or an own '__init__' method
- elif '__init__' in obj.__dict__:
- factory_method = init
- # If not, we take inherited '__new__' or '__init__', if present
- elif new is not None:
- factory_method = new
- elif init is not None:
- factory_method = init
+
+ # Go through the MRO and see if any class has user-defined
+ # pure Python __new__ or __init__ method
+ for base in obj.__mro__:
+ # Now we check if the 'obj' class has an own '__new__' method
+ if new is not None and '__new__' in base.__dict__:
+ factory_method = new
+ break
+ # or an own '__init__' method
+ elif init is not None and '__init__' in base.__dict__:
+ factory_method = init
+ break
if factory_method is not None:
sig = _get_signature_of(factory_method)