@@ -252,147 +252,10 @@ def generate_runtime_init(identifiers, strings):
252252 printer .write (after )
253253
254254
255- #######################################
256- # checks
257-
258- def err (msg ):
259- print (msg , file = sys .stderr )
260-
261-
262- GETTER_RE = re .compile (r'''
263- ^
264- .*?
265- (?:
266- (?:
267- _Py_ID
268- [(]
269- ( \w+ ) # <identifier>
270- [)]
271- )
272- |
273- (?:
274- _Py_STR
275- [(]
276- ( \w+ ) # <literal>
277- [)]
278- )
279- )
280- ''' , re .VERBOSE )
281- TYPESLOTS_RE = re .compile (r'''
282- ^
283- .*?
284- (?:
285- (?:
286- SLOT0 [(] .*?, \s*
287- ( \w+ ) # <slot0>
288- [)]
289- )
290- |
291- (?:
292- SLOT1 [(] .*?, \s*
293- ( \w+ ) # <slot1>
294- , .* [)]
295- )
296- |
297- (?:
298- SLOT1BIN [(] .*?, .*?, \s*
299- ( \w+ ) # <slot1bin>
300- , \s*
301- ( \w+ ) # <reverse>
302- [)]
303- )
304- |
305- (?:
306- SLOT1BINFULL [(] .*?, .*?, .*?, \s*
307- ( \w+ ) # <slot1binfull>
308- , \s*
309- ( \w+ ) # <fullreverse>
310- [)]
311- )
312- |
313- ( SLOT \d .* [^)] $ ) # <wrapped>
314- )
315- ''' , re .VERBOSE )
316-
317- def check_orphan_strings (identifiers ):
318- literals = set (n for n , s in STRING_LITERALS .items () if s )
319- identifiers = set (identifiers )
320- files = glob .iglob (os .path .join (ROOT , '**' , '*.[ch]' ), recursive = True )
321- for i , filename in enumerate (files , start = 1 ):
322- print ('.' , end = '' )
323- if i % 5 == 0 :
324- print (' ' , end = '' )
325- if i % 20 == 0 :
326- print ()
327- if i % 100 == 0 :
328- print ()
329- with open (filename ) as infile :
330- wrapped = None
331- for line in infile :
332- identifier = literal = reverse = None
333-
334- line = line .splitlines ()[0 ]
335- if wrapped :
336- line = f'{ wrapped .rstrip ()} { line } '
337- wrapped = None
338-
339- if os .path .basename (filename ) == '_warnings.c' :
340- m = re .match (r'^.* = GET_WARNINGS_ATTR[(][^,]*, (\w+),' , line )
341- if m :
342- identifier , = m .groups ()
343- elif os .path .basename (filename ) == 'typeobject.c' :
344- m = TYPESLOTS_RE .match (line )
345- if m :
346- (slot0 ,
347- slot1 ,
348- slot1bin , reverse ,
349- slot1binfull , fullreverse ,
350- wrapped ,
351- ) = m .groups ()
352- identifier = slot0 or slot1 or slot1bin or slot1binfull
353- reverse = reverse or fullreverse
354-
355- if not identifier and not literal :
356- m = GETTER_RE .match (line )
357- if not m :
358- continue
359- identifier , literal = m .groups ()
360-
361- if literal :
362- if literals and literal in literals :
363- literals .remove (literal )
364- if identifier :
365- if identifiers and identifier in identifiers :
366- identifiers .remove (identifier )
367- if reverse :
368- if identifiers and reverse in identifiers :
369- identifiers .remove (reverse )
370- if not literals and not identifiers :
371- break
372- else :
373- continue
374- break
375- if i % 20 :
376- print ()
377- if not literals and not identifiers :
378- return
379- print ('ERROR:' , file = sys .stderr )
380- if literals :
381- err (' unused global string literals:' )
382- for name in sorted (literals ):
383- err (f' { name } ' )
384- if identifiers :
385- if literals :
386- print ()
387- err (' unused global identifiers:' )
388- for name in sorted (identifiers ):
389- err (f' { name } ' )
390-
391-
392255#######################################
393256# the script
394257
395- def main (* , check = False ) -> None :
258+ def main () -> None :
396259 identifiers = set (IDENTIFIERS )
397260 strings = dict (STRING_LITERALS )
398261 for name , string , filename , lno , _ in iter_global_strings ():
@@ -408,13 +271,9 @@ def main(*, check=False) -> None:
408271 generate_global_strings (identifiers , strings )
409272 generate_runtime_init (identifiers , strings )
410273
411- if check :
412- check_orphan_strings (identifiers )
413-
414274
415275if __name__ == '__main__' :
416276 import argparse
417277 parser = argparse .ArgumentParser ()
418- parser .add_argument ('--check' , action = 'store_true' )
419278 args = parser .parse_args ()
420279 main (** vars (args ))
0 commit comments