Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 232bfbc

Browse files
committed
Fix stripping of C type names
1 parent 0b20493 commit 232bfbc

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

mypy/stubgenc.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,16 +199,16 @@ def strip_or_import(typ: str, module: ModuleType, imports: List[str]) -> str:
199199
module: in which this type is used
200200
imports: list of import statements (may be modified during the call)
201201
"""
202-
arg_type = typ
203-
if module and typ.startswith(module.__name__):
204-
arg_type = typ[len(module.__name__) + 1:]
202+
stripped_type = typ
203+
if module and typ.startswith(module.__name__ + '.'):
204+
stripped_type = typ[len(module.__name__) + 1:]
205205
elif '.' in typ:
206-
arg_module = arg_type[:arg_type.rindex('.')]
206+
arg_module = typ[:typ.rindex('.')]
207207
if arg_module == 'builtins':
208-
arg_type = arg_type[len('builtins') + 1:]
208+
stripped_type = typ[len('builtins') + 1:]
209209
else:
210210
imports.append('import %s' % (arg_module,))
211-
return arg_type
211+
return stripped_type
212212

213213

214214
def generate_c_property_stub(name: str, obj: object, output: List[str], readonly: bool) -> None:
@@ -295,7 +295,7 @@ def generate_c_type_stub(module: ModuleType,
295295
if bases:
296296
bases_str = '(%s)' % ', '.join(
297297
strip_or_import(
298-
'%s.%s' % (base.__module__, base.__name__),
298+
get_type_fullname(base),
299299
module,
300300
imports
301301
) for base in bases
@@ -314,6 +314,10 @@ def generate_c_type_stub(module: ModuleType,
314314
output.append(' %s' % prop)
315315

316316

317+
def get_type_fullname(typ: type) -> str:
318+
return '%s.%s' % (typ.__module__, typ.__name__)
319+
320+
317321
def method_name_sort_key(name: str) -> Tuple[int, str]:
318322
"""Sort methods in classes in a typical order.
319323

0 commit comments

Comments
 (0)