@@ -250,7 +250,8 @@ def is_static_property(obj: object) -> bool:
250250
251251def generate_c_property_stub (name : str , obj : object ,
252252 static_properties : List [str ],
253- properties : List [str ], readonly : bool ,
253+ rw_properties : List [str ],
254+ ro_properties : List [str ], readonly : bool ,
254255 module : Optional [ModuleType ] = None ,
255256 imports : Optional [List [str ]] = None ) -> None :
256257 """Generate property stub using introspection of 'obj'.
@@ -286,11 +287,11 @@ def infer_prop_type(docstr: Optional[str]) -> Optional[str]:
286287 '{}: ClassVar[{}] = ...{}' .format (name , inferred , trailing_comment )
287288 )
288289 else : # regular property
289- properties . append ( '@property' )
290- properties . append ( 'def {}(self) -> {}: ...' . format ( name , inferred ) )
291- if not readonly :
292- properties . append ( '@{}.setter' . format ( name ))
293- properties .append ('def {}(self, val : {}) -> None: ... ' .format (name , inferred ))
290+ if readonly :
291+ ro_properties . append ( '@property' )
292+ ro_properties . append ( 'def {}(self) -> {}: ...' . format ( name , inferred ))
293+ else :
294+ rw_properties .append ('{} : {}' .format (name , inferred ))
294295
295296
296297def generate_c_type_stub (module : ModuleType ,
@@ -312,7 +313,8 @@ def generate_c_type_stub(module: ModuleType,
312313 methods = [] # type: List[str]
313314 types = [] # type: List[str]
314315 static_properties = [] # type: List[str]
315- properties = [] # type: List[str]
316+ rw_properties = [] # type: List[str]
317+ ro_properties = [] # type: List[str]
316318 done = set () # type: Set[str]
317319 for attr , value in items :
318320 if is_c_method (value ) or is_c_classmethod (value ):
@@ -336,7 +338,7 @@ def generate_c_type_stub(module: ModuleType,
336338 class_sigs = class_sigs )
337339 elif is_c_property (value ):
338340 done .add (attr )
339- generate_c_property_stub (attr , value , static_properties , properties ,
341+ generate_c_property_stub (attr , value , static_properties , rw_properties , ro_properties ,
340342 is_c_property_readonly (value ),
341343 module = module , imports = imports )
342344 elif is_c_type (value ):
@@ -375,7 +377,7 @@ def generate_c_type_stub(module: ModuleType,
375377 )
376378 else :
377379 bases_str = ''
378- if types or static_properties or methods or properties :
380+ if types or static_properties or rw_properties or methods or ro_properties :
379381 output .append ('class %s%s:' % (class_name , bases_str ))
380382 for line in types :
381383 if output and output [- 1 ] and \
@@ -384,9 +386,11 @@ def generate_c_type_stub(module: ModuleType,
384386 output .append (' ' + line )
385387 for line in static_properties :
386388 output .append (' %s' % line )
389+ for line in rw_properties :
390+ output .append (' %s' % line )
387391 for line in methods :
388392 output .append (' %s' % line )
389- for line in properties :
393+ for line in ro_properties :
390394 output .append (' %s' % line )
391395 else :
392396 output .append ('class %s%s: ...' % (class_name , bases_str ))
0 commit comments