1- # -*- coding: utf-8 -*-
21"""
32 c_annotations.py
43 ~~~~~~~~~~~~~~~~
3433
3534REST_ROLE_MAP = {
3635 'function' : 'func' ,
37- 'var' : 'data' ,
38- 'type' : 'type' ,
3936 'macro' : 'macro' ,
40- 'type' : 'type' ,
4137 'member' : 'member' ,
38+ 'type' : 'type' ,
39+ 'var' : 'data' ,
4240}
4341
4442
@@ -63,15 +61,15 @@ def __init__(self, name):
6361class Annotations :
6462 def __init__ (self , refcount_filename , stable_abi_file ):
6563 self .refcount_data = {}
66- with open (refcount_filename , 'r ' ) as fp :
64+ with open (refcount_filename , encoding = 'utf8 ' ) as fp :
6765 for line in fp :
6866 line = line .strip ()
6967 if line [:1 ] in ("" , "#" ):
7068 # blank lines and comments
7169 continue
7270 parts = line .split (":" , 4 )
7371 if len (parts ) != 5 :
74- raise ValueError ("Wrong field count in %r" % line )
72+ raise ValueError (f "Wrong field count in { line !r } " )
7573 function , type , arg , refcount , comment = parts
7674 # Get the entry, creating it if needed:
7775 try :
@@ -91,9 +89,8 @@ def __init__(self, refcount_filename, stable_abi_file):
9189 entry .result_refs = refcount
9290
9391 self .stable_abi_data = {}
94- with open (stable_abi_file , 'r ' ) as fp :
92+ with open (stable_abi_file , encoding = 'utf8 ' ) as fp :
9593 for record in csv .DictReader (fp ):
96- role = record ['role' ]
9794 name = record ['name' ]
9895 self .stable_abi_data [name ] = record
9996
@@ -180,13 +177,17 @@ def add_annotations(self, app, doctree):
180177 continue
181178 elif not entry .result_type .endswith ("Object*" ):
182179 continue
180+ classes = ['refcount' ]
183181 if entry .result_refs is None :
184182 rc = sphinx_gettext ('Return value: Always NULL.' )
183+ classes .append ('return_null' )
185184 elif entry .result_refs :
186185 rc = sphinx_gettext ('Return value: New reference.' )
186+ classes .append ('return_new_ref' )
187187 else :
188188 rc = sphinx_gettext ('Return value: Borrowed reference.' )
189- node .insert (0 , nodes .emphasis (rc , rc , classes = ['refcount' ]))
189+ classes .append ('return_borrowed_ref' )
190+ node .insert (0 , nodes .emphasis (rc , rc , classes = classes ))
190191
191192
192193def init_annotations (app ):
@@ -228,6 +229,7 @@ def setup(app):
228229 'stableabi' : directives .flag ,
229230 }
230231 old_handle_signature = CObject .handle_signature
232+
231233 def new_handle_signature (self , sig , signode ):
232234 signode .parent ['stableabi' ] = 'stableabi' in self .options
233235 return old_handle_signature (self , sig , signode )
0 commit comments