20
20
21
21
class FormatHelper :
22
22
COMMENT_TAG = "<!--LLVM CODE FORMAT COMMENT: {fmt}-->"
23
- name = "unknown"
23
+ name : str
24
+ friendly_name : str
24
25
25
26
@property
26
27
def comment_tag (self ) -> str :
27
28
return self .COMMENT_TAG .replace ("fmt" , self .name )
28
29
29
- def format_run (self , changed_files : [str ], args : argparse .Namespace ) -> str | None :
30
- pass
30
+ @property
31
+ def instructions (self ) -> str :
32
+ raise NotImplementedError ()
33
+
34
+ def format_run (
35
+ self , changed_files : list [str ], args : argparse .Namespace
36
+ ) -> str | None :
37
+ raise NotImplementedError ()
31
38
32
39
def pr_comment_text (self , diff : str ) -> str :
33
40
return f"""
@@ -66,7 +73,7 @@ def find_comment(
66
73
return comment
67
74
return None
68
75
69
- def update_pr (self , diff : str , args : argparse .Namespace ):
76
+ def update_pr (self , diff : str , args : argparse .Namespace ) -> None :
70
77
repo = github .Github (args .token ).get_repo (args .repo )
71
78
pr = repo .get_issue (args .issue_number ).as_pull_request ()
72
79
@@ -78,7 +85,7 @@ def update_pr(self, diff: str, args: argparse.Namespace):
78
85
else :
79
86
pr .as_issue ().create_comment (pr_text )
80
87
81
- def update_pr_success (self , args : argparse .Namespace ):
88
+ def update_pr_success (self , args : argparse .Namespace ) -> None :
82
89
repo = github .Github (args .token ).get_repo (args .repo )
83
90
pr = repo .get_issue (args .issue_number ).as_pull_request ()
84
91
@@ -91,7 +98,7 @@ def update_pr_success(self, args: argparse.Namespace):
91
98
"""
92
99
)
93
100
94
- def run (self , changed_files : [str ], args : argparse .Namespace ):
101
+ def run (self , changed_files : list [str ], args : argparse .Namespace ) -> bool :
95
102
diff = self .format_run (changed_files , args )
96
103
if diff :
97
104
self .update_pr (diff , args )
@@ -106,11 +113,11 @@ class ClangFormatHelper(FormatHelper):
106
113
friendly_name = "C/C++ code formatter"
107
114
108
115
@property
109
- def instructions (self ):
116
+ def instructions (self ) -> str :
110
117
return " " .join (self .cf_cmd )
111
118
112
119
@cached_property
113
- def libcxx_excluded_files (self ):
120
+ def libcxx_excluded_files (self ) -> list [ str ] :
114
121
with open ("libcxx/utils/data/ignore_format.txt" , "r" ) as ifd :
115
122
return [excl .strip () for excl in ifd .readlines ()]
116
123
@@ -120,7 +127,7 @@ def should_be_excluded(self, path: str) -> bool:
120
127
return True
121
128
return False
122
129
123
- def filter_changed_files (self , changed_files : [str ]) -> [str ]:
130
+ def filter_changed_files (self , changed_files : list [str ]) -> list [str ]:
124
131
filtered_files = []
125
132
for path in changed_files :
126
133
_ , ext = os .path .splitext (path )
@@ -129,10 +136,12 @@ def filter_changed_files(self, changed_files: [str]) -> [str]:
129
136
filtered_files .append (path )
130
137
return filtered_files
131
138
132
- def format_run (self , changed_files : [str ], args : argparse .Namespace ) -> str | None :
139
+ def format_run (
140
+ self , changed_files : list [str ], args : argparse .Namespace
141
+ ) -> str | None :
133
142
cpp_files = self .filter_changed_files (changed_files )
134
143
if not cpp_files :
135
- return
144
+ return None
136
145
cf_cmd = [
137
146
"git-clang-format" ,
138
147
"--diff" ,
@@ -156,10 +165,10 @@ class DarkerFormatHelper(FormatHelper):
156
165
friendly_name = "Python code formatter"
157
166
158
167
@property
159
- def instructions (self ):
168
+ def instructions (self ) -> str :
160
169
return " " .join (self .darker_cmd )
161
170
162
- def filter_changed_files (self , changed_files : [str ]) -> [str ]:
171
+ def filter_changed_files (self , changed_files : list [str ]) -> list [str ]:
163
172
filtered_files = []
164
173
for path in changed_files :
165
174
name , ext = os .path .splitext (path )
@@ -168,10 +177,12 @@ def filter_changed_files(self, changed_files: [str]) -> [str]:
168
177
169
178
return filtered_files
170
179
171
- def format_run (self , changed_files : [str ], args : argparse .Namespace ) -> str | None :
180
+ def format_run (
181
+ self , changed_files : list [str ], args : argparse .Namespace
182
+ ) -> str | None :
172
183
py_files = self .filter_changed_files (changed_files )
173
184
if not py_files :
174
- return
185
+ return None
175
186
darker_cmd = [
176
187
"darker" ,
177
188
"--check" ,
0 commit comments