File tree 3 files changed +31
-25
lines changed 3 files changed +31
-25
lines changed Original file line number Diff line number Diff line change 23
23
import pprint
24
24
import re
25
25
import shlex
26
- import string
27
26
import sys
28
27
import textwrap
29
28
@@ -270,24 +269,6 @@ def __init__(self) -> None:
270
269
self .unlock : list [str ] = []
271
270
272
271
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
-
291
272
class Language (metaclass = abc .ABCMeta ):
292
273
293
274
start_line = ""
@@ -341,7 +322,7 @@ def assert_only_one(
341
322
fields = ['dsl_name' ]
342
323
fields .extend (additional_fields )
343
324
line : str = getattr (self , attr )
344
- fcf = FormatCounterFormatter ()
325
+ fcf = libclinic . FormatCounterFormatter ()
345
326
fcf .format (line )
346
327
def local_fail (should_be_there_but_isnt : bool ) -> None :
347
328
if should_be_there_but_isnt :
Original file line number Diff line number Diff line change 16
16
wrapped_c_string_literal ,
17
17
)
18
18
from .utils import (
19
- create_regex ,
19
+ FormatCounterFormatter ,
20
20
compute_checksum ,
21
+ create_regex ,
21
22
write_file ,
22
23
)
23
24
39
40
"wrapped_c_string_literal" ,
40
41
41
42
# Utility functions
42
- "create_regex " ,
43
+ "FormatCounterFormatter " ,
43
44
"compute_checksum" ,
45
+ "create_regex" ,
44
46
"write_file" ,
45
47
]
46
48
Original file line number Diff line number Diff line change
1
+ import collections
1
2
import hashlib
2
- import re
3
3
import os
4
+ import re
5
+ import string
6
+ from typing import Literal
4
7
5
8
6
9
def write_file (filename : str , new_contents : str ) -> None :
@@ -39,7 +42,27 @@ def create_regex(
39
42
group_re = r"\w+" if word else ".+"
40
43
before = re .escape (before )
41
44
after = re .escape (after )
42
- pattern = fr "{ before } ({ group_re } ){ after } "
45
+ pattern = rf "{ before } ({ group_re } ){ after } "
43
46
if whole_line :
44
- pattern = fr "^{ pattern } $"
47
+ pattern = rf "^{ pattern } $"
45
48
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