@@ -250,7 +250,8 @@ def is_static_property(obj: object) -> bool:
250
250
251
251
def generate_c_property_stub (name : str , obj : object ,
252
252
static_properties : List [str ],
253
- properties : List [str ], readonly : bool ,
253
+ rw_properties : List [str ],
254
+ ro_properties : List [str ], readonly : bool ,
254
255
module : Optional [ModuleType ] = None ,
255
256
imports : Optional [List [str ]] = None ) -> None :
256
257
"""Generate property stub using introspection of 'obj'.
@@ -286,11 +287,11 @@ def infer_prop_type(docstr: Optional[str]) -> Optional[str]:
286
287
'{}: ClassVar[{}] = ...{}' .format (name , inferred , trailing_comment )
287
288
)
288
289
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 ))
294
295
295
296
296
297
def generate_c_type_stub (module : ModuleType ,
@@ -312,7 +313,8 @@ def generate_c_type_stub(module: ModuleType,
312
313
methods = [] # type: List[str]
313
314
types = [] # type: List[str]
314
315
static_properties = [] # type: List[str]
315
- properties = [] # type: List[str]
316
+ rw_properties = [] # type: List[str]
317
+ ro_properties = [] # type: List[str]
316
318
done = set () # type: Set[str]
317
319
for attr , value in items :
318
320
if is_c_method (value ) or is_c_classmethod (value ):
@@ -336,7 +338,7 @@ def generate_c_type_stub(module: ModuleType,
336
338
class_sigs = class_sigs )
337
339
elif is_c_property (value ):
338
340
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 ,
340
342
is_c_property_readonly (value ),
341
343
module = module , imports = imports )
342
344
elif is_c_type (value ):
@@ -375,7 +377,7 @@ def generate_c_type_stub(module: ModuleType,
375
377
)
376
378
else :
377
379
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 :
379
381
output .append ('class %s%s:' % (class_name , bases_str ))
380
382
for line in types :
381
383
if output and output [- 1 ] and \
@@ -384,9 +386,11 @@ def generate_c_type_stub(module: ModuleType,
384
386
output .append (' ' + line )
385
387
for line in static_properties :
386
388
output .append (' %s' % line )
389
+ for line in rw_properties :
390
+ output .append (' %s' % line )
387
391
for line in methods :
388
392
output .append (' %s' % line )
389
- for line in properties :
393
+ for line in ro_properties :
390
394
output .append (' %s' % line )
391
395
else :
392
396
output .append ('class %s%s: ...' % (class_name , bases_str ))
0 commit comments