Skip to content

Commit 0305fab

Browse files
committed
Fixed stubgen parsing generics from C extensions
1 parent d49e245 commit 0305fab

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

mypy/stubgenc.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,16 @@ def strip_or_import(typ: str, module: ModuleType, imports: List[str]) -> str:
201201
imports: list of import statements (may be modified during the call)
202202
"""
203203
stripped_type = typ
204-
if module and typ.startswith(module.__name__ + '.'):
204+
if any(c in typ for c in '[,'):
205+
for subtyp in re.split(r'\[|,\]', typ):
206+
strip_or_import(subtyp.strip(), module, imports)
207+
if module:
208+
stripped_type = re.sub(
209+
r'(^|[\[, ]+)' + re.escape(module.__name__ + '.'),
210+
r'\1',
211+
typ,
212+
)
213+
elif module and typ.startswith(module.__name__ + '.'):
205214
stripped_type = typ[len(module.__name__) + 1:]
206215
elif '.' in typ:
207216
arg_module = typ[:typ.rindex('.')]

0 commit comments

Comments
 (0)