File tree Expand file tree Collapse file tree 3 files changed +31
-25
lines changed
Expand file tree Collapse file tree 3 files changed +31
-25
lines changed Original file line number Diff line number Diff line change 2323import pprint
2424import re
2525import shlex
26- import string
2726import sys
2827import textwrap
2928
@@ -270,24 +269,6 @@ def __init__(self) -> None:
270269 self .unlock : list [str ] = []
271270
272271
273- class FormatCounterFormatter (string .Formatter ):
274- """
275- This counts how many instances of each formatter
276- "replacement string" appear in the format string.
277-
278- e.g. after evaluating "string {a}, {b}, {c}, {a}"
279- the counts dict would now look like
280- {'a': 2, 'b': 1, 'c': 1}
281- """
282- def __init__ (self ) -> None :
283- self .counts = collections .Counter [str ]()
284-
285- def get_value (
286- self , key : str , args : object , kwargs : object # type: ignore[override]
287- ) -> Literal ['' ]:
288- self .counts [key ] += 1
289- return ''
290-
291272class Language (metaclass = abc .ABCMeta ):
292273
293274 start_line = ""
@@ -341,7 +322,7 @@ def assert_only_one(
341322 fields = ['dsl_name' ]
342323 fields .extend (additional_fields )
343324 line : str = getattr (self , attr )
344- fcf = FormatCounterFormatter ()
325+ fcf = libclinic . FormatCounterFormatter ()
345326 fcf .format (line )
346327 def local_fail (should_be_there_but_isnt : bool ) -> None :
347328 if should_be_there_but_isnt :
Original file line number Diff line number Diff line change 1616 wrapped_c_string_literal ,
1717)
1818from .utils import (
19- create_regex ,
19+ FormatCounterFormatter ,
2020 compute_checksum ,
21+ create_regex ,
2122 write_file ,
2223)
2324
3940 "wrapped_c_string_literal" ,
4041
4142 # Utility functions
42- "create_regex " ,
43+ "FormatCounterFormatter " ,
4344 "compute_checksum" ,
45+ "create_regex" ,
4446 "write_file" ,
4547]
4648
Original file line number Diff line number Diff line change 1+ import collections
12import hashlib
2- import re
33import os
4+ import re
5+ import string
6+ from typing import Literal
47
58
69def write_file (filename : str , new_contents : str ) -> None :
@@ -39,7 +42,27 @@ def create_regex(
3942 group_re = r"\w+" if word else ".+"
4043 before = re .escape (before )
4144 after = re .escape (after )
42- pattern = fr "{ before } ({ group_re } ){ after } "
45+ pattern = rf "{ before } ({ group_re } ){ after } "
4346 if whole_line :
44- pattern = fr "^{ pattern } $"
47+ pattern = rf "^{ pattern } $"
4548 return re .compile (pattern )
49+
50+
51+ class FormatCounterFormatter (string .Formatter ):
52+ """
53+ This counts how many instances of each formatter
54+ "replacement string" appear in the format string.
55+
56+ e.g. after evaluating "string {a}, {b}, {c}, {a}"
57+ the counts dict would now look like
58+ {'a': 2, 'b': 1, 'c': 1}
59+ """
60+
61+ def __init__ (self ) -> None :
62+ self .counts = collections .Counter [str ]()
63+
64+ def get_value (
65+ self , key : str , args : object , kwargs : object # type: ignore[override]
66+ ) -> Literal ["" ]:
67+ self .counts [key ] += 1
68+ return ""
You can’t perform that action at this time.
0 commit comments