@@ -69,7 +69,7 @@ def generate_stub_for_c_module(module_name: str,
6969 if name .startswith ('__' ) and name .endswith ('__' ):
7070 continue
7171 if name not in done and not inspect .ismodule (obj ):
72- type_str = strip_or_import (type (obj ). __name__ , module , imports )
72+ type_str = strip_or_import (get_type_fullname ( type (obj )) , module , imports )
7373 variables .append ('%s: %s' % (name , type_str ))
7474 output = []
7575 for line in sorted (set (imports )):
@@ -286,6 +286,7 @@ def generate_c_type_stub(module: ModuleType,
286286 obj_dict = getattr (obj , '__dict__' ) # type: Mapping[str, Any] # noqa
287287 items = sorted (obj_dict .items (), key = lambda x : method_name_sort_key (x [0 ]))
288288 methods = [] # type: List[str]
289+ types = [] # type: List[str]
289290 properties = [] # type: List[str]
290291 done = set () # type: Set[str]
291292 for attr , value in items :
@@ -312,14 +313,18 @@ def generate_c_type_stub(module: ModuleType,
312313 done .add (attr )
313314 generate_c_property_stub (attr , value , properties , is_c_property_readonly (value ),
314315 module = module , imports = imports )
316+ elif is_c_type (value ):
317+ generate_c_type_stub (module , attr , value , types , imports = imports , sigs = sigs ,
318+ class_sigs = class_sigs )
319+ done .add (attr )
315320
316321 variables = []
317322 for attr , value in items :
318323 if is_skipped_attribute (attr ):
319324 continue
320325 if attr not in done :
321326 variables .append ('%s: %s = ...' % (
322- attr , strip_or_import (type (value ). __name__ , module , imports )))
327+ attr , strip_or_import (get_type_fullname ( type (value )) , module , imports )))
323328 all_bases = obj .mro ()
324329 if all_bases [- 1 ] is object :
325330 # TODO: Is this always object?
@@ -345,10 +350,15 @@ def generate_c_type_stub(module: ModuleType,
345350 )
346351 else :
347352 bases_str = ''
348- if not methods and not variables and not properties :
353+ if not methods and not variables and not properties and not types :
349354 output .append ('class %s%s: ...' % (class_name , bases_str ))
350355 else :
351356 output .append ('class %s%s:' % (class_name , bases_str ))
357+ for line in types :
358+ if output and output [- 1 ] and \
359+ not output [- 1 ].startswith ('class' ) and line .startswith ('class' ):
360+ output .append ('' )
361+ output .append (' ' + line )
352362 for variable in variables :
353363 output .append (' %s' % variable )
354364 for method in methods :
@@ -358,7 +368,7 @@ def generate_c_type_stub(module: ModuleType,
358368
359369
360370def get_type_fullname (typ : type ) -> str :
361- return '%s.%s' % (typ .__module__ , typ .__name__ )
371+ return '%s.%s' % (typ .__module__ , getattr ( typ , '__qualname__' , typ .__name__ ) )
362372
363373
364374def method_name_sort_key (name : str ) -> Tuple [int , str ]:
0 commit comments