Skip to content

Commit 7a09b7f

Browse files
committed
Deduplicate functions/arguments in stubgen
1 parent c033dbd commit 7a09b7f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

mypy/stubgenc.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ def generate_c_function_stub(module, name, obj, output, self_var=None, sigs={},
109109
else:
110110
sig = sigs.get(name, '(*args, **kwargs)')
111111
sig = sig[1:-1]
112-
if not sig:
112+
if sig:
113+
if sig.split(',', 1)[0] == self_var:
114+
self_arg = ''
115+
else:
113116
self_arg = self_arg.replace(', ', '')
114117
output.append('def %s(%s%s): pass' % (name, self_arg, sig))
115118

@@ -129,6 +132,11 @@ def generate_c_type_stub(module, class_name, obj, output, sigs={}, class_sigs={}
129132
self_var = 'self'
130133
if attr == '__new__':
131134
# TODO: We should support __new__.
135+
if '__init__' in obj.__dict__:
136+
# Avoid duplicate functions if both are present.
137+
# But is there any case where .__new__() has a
138+
# better signature than __init__() ?
139+
continue
132140
attr = '__init__'
133141
generate_c_function_stub(module, attr, value, methods, self_var, sigs=sigs,
134142
class_name=class_name, class_sigs=class_sigs)

0 commit comments

Comments
 (0)