@@ -361,15 +361,15 @@ class NameMangler(ast3.NodeTransformer):
361
361
362
362
_name_complete : str
363
363
_name_trimmed : str
364
- _future_annotations : bool
364
+ _mangle_annotations : bool
365
365
_unmangled_args : set [str ]
366
366
367
367
_MANGLE_ARGS : bool = False
368
368
369
- def __init__ (self , classname : str , future_annotations : bool ) -> None :
369
+ def __init__ (self , classname : str , mangle_annotations : bool ) -> None :
370
370
self ._name_complete = classname
371
371
self ._name_trimmed = classname .lstrip ("_" )
372
- self ._future_annotations = future_annotations
372
+ self ._mangle_annotations = mangle_annotations
373
373
self ._unmangled_args = set ()
374
374
375
375
def _mangle (self , name : str ) -> str :
@@ -394,11 +394,11 @@ def _visit_funcdef(self, node: _T_FuncDef) -> _T_FuncDef:
394
394
if self ._MANGLE_ARGS :
395
395
mangler = self
396
396
else :
397
- mangler = NameMangler (self ._name_complete , self ._future_annotations )
397
+ mangler = NameMangler (self ._name_complete , self ._mangle_annotations )
398
398
mangler .visit (node .args )
399
399
for dec in node .decorator_list :
400
400
mangler .visit (dec )
401
- if (node .returns is not None ) and not self . _future_annotations :
401
+ if self . _mangle_annotations and (node .returns is not None ):
402
402
mangler .visit (node .returns )
403
403
for stmt in node .body :
404
404
mangler .visit (stmt )
@@ -409,7 +409,7 @@ def visit_arg(self, node: ast3.arg) -> ast3.arg:
409
409
node .arg = self ._mangle (node .arg )
410
410
else :
411
411
self ._unmangled_args .add (node .arg )
412
- if (node .annotation is not None ) and not self . _future_annotations :
412
+ if self . _mangle_annotations and (node .annotation is not None ):
413
413
self .visit (node .annotation )
414
414
return node
415
415
@@ -426,7 +426,7 @@ def visit_ClassDef(self, node: ast3.ClassDef) -> ast3.ClassDef:
426
426
else :
427
427
for dec in node .decorator_list :
428
428
self .visit (dec )
429
- NameMangler (node .name , self ._future_annotations ).visit (node )
429
+ NameMangler (node .name , self ._mangle_annotations ).visit (node )
430
430
node .name = self ._mangle (node .name )
431
431
return node
432
432
@@ -450,7 +450,7 @@ def visit_AnnAssign(self, node: ast3.AnnAssign) -> ast3.AnnAssign:
450
450
self .visit (node .target )
451
451
if node .value is not None :
452
452
self .visit (node .value )
453
- if not self ._future_annotations :
453
+ if self ._mangle_annotations :
454
454
self .visit (node .annotation )
455
455
return node
456
456
@@ -1235,13 +1235,13 @@ def visit_ClassDef(self, n: ast3.ClassDef) -> ClassDef:
1235
1235
if sys .version_info >= (3 , 12 ) and n .type_params :
1236
1236
explicit_type_params = self .translate_type_params (n .type_params )
1237
1237
1238
- future_annotations = any (
1238
+ mangle_annotations = not self . is_stub and not any (
1239
1239
isinstance (i , ImportFrom )
1240
1240
and (i .id == "__future__" )
1241
1241
and any (j [0 ] == "annotations" for j in i .names )
1242
1242
for i in self .imports
1243
1243
)
1244
- NameMangler (n .name , future_annotations ).visit (n )
1244
+ NameMangler (n .name , mangle_annotations ).visit (n )
1245
1245
1246
1246
cdef = ClassDef (
1247
1247
n .name ,
0 commit comments