|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2020 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 |
|
7 """ |
|
8 Module implementing message translations for the code style plugin messages |
|
9 (miscellaneous part). |
|
10 """ |
|
11 |
|
12 from PyQt5.QtCore import QCoreApplication |
|
13 |
|
14 _miscellaneousMessages = { |
|
15 "M101": QCoreApplication.translate( |
|
16 "MiscellaneousChecker", |
|
17 "coding magic comment not found"), |
|
18 "M102": QCoreApplication.translate( |
|
19 "MiscellaneousChecker", |
|
20 "unknown encoding ({0}) found in coding magic comment"), |
|
21 "M111": QCoreApplication.translate( |
|
22 "MiscellaneousChecker", |
|
23 "copyright notice not present"), |
|
24 "M112": QCoreApplication.translate( |
|
25 "MiscellaneousChecker", |
|
26 "copyright notice contains invalid author"), |
|
27 "M131": QCoreApplication.translate( |
|
28 "MiscellaneousChecker", |
|
29 '"{0}" is a Python builtin and is being shadowed; ' |
|
30 'consider renaming the variable'), |
|
31 "M132": QCoreApplication.translate( |
|
32 "MiscellaneousChecker", |
|
33 '"{0}" is used as an argument and thus shadows a ' |
|
34 'Python builtin; consider renaming the argument'), |
|
35 "M181": QCoreApplication.translate( |
|
36 "MiscellaneousChecker", |
|
37 'unnecessary generator - rewrite as a list comprehension'), |
|
38 "M182": QCoreApplication.translate( |
|
39 "MiscellaneousChecker", |
|
40 'unnecessary generator - rewrite as a set comprehension'), |
|
41 "M183": QCoreApplication.translate( |
|
42 "MiscellaneousChecker", |
|
43 'unnecessary generator - rewrite as a dict comprehension'), |
|
44 "M184": QCoreApplication.translate( |
|
45 "MiscellaneousChecker", |
|
46 'unnecessary list comprehension - rewrite as a set comprehension'), |
|
47 "M185": QCoreApplication.translate( |
|
48 "MiscellaneousChecker", |
|
49 'unnecessary list comprehension - rewrite as a dict comprehension'), |
|
50 "M186": QCoreApplication.translate( |
|
51 "MiscellaneousChecker", |
|
52 'unnecessary {0} call - rewrite as a literal'), |
|
53 "M187": QCoreApplication.translate( |
|
54 "MiscellaneousChecker", |
|
55 'unnecessary list comprehension - "{0}" can take a generator'), |
|
56 "M191": QCoreApplication.translate( |
|
57 "MiscellaneousChecker", |
|
58 'unnecessary {0} literal - rewrite as a {1} literal'), |
|
59 "M192": QCoreApplication.translate( |
|
60 "MiscellaneousChecker", |
|
61 'unnecessary {0} passed to tuple() - rewrite as a {1} literal'), |
|
62 "M193": QCoreApplication.translate( |
|
63 "MiscellaneousChecker", |
|
64 'unnecessary {0} passed to list() - rewrite as a {1} literal'), |
|
65 "M195": QCoreApplication.translate( |
|
66 "MiscellaneousChecker", |
|
67 'unnecessary list call - remove the outer call to list()'), |
|
68 "M196": QCoreApplication.translate( |
|
69 "MiscellaneousChecker", |
|
70 'unnecessary list comprehension - "in" can take a generator'), |
|
71 "M197": QCoreApplication.translate( |
|
72 "MiscellaneousChecker", |
|
73 'unnecessary {0} passed to tuple() - remove the outer call to {1}()'), |
|
74 "M198": QCoreApplication.translate( |
|
75 "MiscellaneousChecker", |
|
76 'unnecessary {0} passed to list() - remove the outer call to {1}()'), |
|
77 |
|
78 "M201": QCoreApplication.translate( |
|
79 "MiscellaneousChecker", |
|
80 "sort keys - '{0}' should be before '{1}'"), |
|
81 |
|
82 "M301": QCoreApplication.translate( |
|
83 "MiscellaneousChecker", |
|
84 "use of 'datetime.datetime()' without 'tzinfo' argument should be" |
|
85 " avoided"), |
|
86 "M302": QCoreApplication.translate( |
|
87 "MiscellaneousChecker", |
|
88 "use of 'datetime.datetime.today()' should be avoided.\n" |
|
89 "Use 'datetime.datetime.now(tz=)' instead."), |
|
90 "M303": QCoreApplication.translate( |
|
91 "MiscellaneousChecker", |
|
92 "use of 'datetime.datetime.utcnow()' should be avoided.\n" |
|
93 "Use 'datetime.datetime.now(tz=)' instead."), |
|
94 "M304": QCoreApplication.translate( |
|
95 "MiscellaneousChecker", |
|
96 "use of 'datetime.datetime.utcfromtimestamp()' should be avoided.\n" |
|
97 "Use 'datetime.datetime.fromtimestamp(, tz=)' instead."), |
|
98 "M305": QCoreApplication.translate( |
|
99 "MiscellaneousChecker", |
|
100 "use of 'datetime.datetime.now()' without 'tz' argument should be" |
|
101 " avoided"), |
|
102 "M306": QCoreApplication.translate( |
|
103 "MiscellaneousChecker", |
|
104 "use of 'datetime.datetime.fromtimestamp()' without 'tz' argument" |
|
105 " should be avoided"), |
|
106 "M307": QCoreApplication.translate( |
|
107 "MiscellaneousChecker", |
|
108 "use of 'datetime.datetime.strptime()' should be followed by" |
|
109 " '.replace(tzinfo=)'"), |
|
110 "M308": QCoreApplication.translate( |
|
111 "MiscellaneousChecker", |
|
112 "use of 'datetime.datetime.fromordinal()' should be avoided"), |
|
113 "M311": QCoreApplication.translate( |
|
114 "MiscellaneousChecker", |
|
115 "use of 'datetime.date()' should be avoided.\n" |
|
116 "Use 'datetime.datetime(, tzinfo=).date()' instead."), |
|
117 "M312": QCoreApplication.translate( |
|
118 "MiscellaneousChecker", |
|
119 "use of 'datetime.date.today()' should be avoided.\n" |
|
120 "Use 'datetime.datetime.now(tz=).date()' instead."), |
|
121 "M313": QCoreApplication.translate( |
|
122 "MiscellaneousChecker", |
|
123 "use of 'datetime.date.fromtimestamp()' should be avoided.\n" |
|
124 "Use 'datetime.datetime.fromtimestamp(tz=).date()' instead."), |
|
125 "M314": QCoreApplication.translate( |
|
126 "MiscellaneousChecker", |
|
127 "use of 'datetime.date.fromordinal()' should be avoided"), |
|
128 "M315": QCoreApplication.translate( |
|
129 "MiscellaneousChecker", |
|
130 "use of 'datetime.date.fromisoformat()' should be avoided"), |
|
131 "M321": QCoreApplication.translate( |
|
132 "MiscellaneousChecker", |
|
133 "use of 'datetime.time()' without 'tzinfo' argument should be" |
|
134 " avoided"), |
|
135 |
|
136 "M401": QCoreApplication.translate( |
|
137 "MiscellaneousChecker", |
|
138 "'sys.version[:3]' referenced (Python 3.10), use 'sys.version_info'"), |
|
139 "M402": QCoreApplication.translate( |
|
140 "MiscellaneousChecker", |
|
141 "'sys.version[2]' referenced (Python 3.10), use 'sys.version_info'"), |
|
142 "M403": QCoreApplication.translate( |
|
143 "MiscellaneousChecker", |
|
144 "'sys.version' compared to string (Python 3.10), use" |
|
145 " 'sys.version_info'"), |
|
146 "M411": QCoreApplication.translate( |
|
147 "MiscellaneousChecker", |
|
148 "'sys.version_info[0] == 3' referenced (Python 4), use '>='"), |
|
149 "M412": QCoreApplication.translate( |
|
150 "MiscellaneousChecker", |
|
151 "'six.PY3' referenced (Python 4), use 'not six.PY2'"), |
|
152 "M413": QCoreApplication.translate( |
|
153 "MiscellaneousChecker", |
|
154 "'sys.version_info[1]' compared to integer (Python 4)," |
|
155 " compare 'sys.version_info' to tuple"), |
|
156 "M414": QCoreApplication.translate( |
|
157 "MiscellaneousChecker", |
|
158 "'sys.version_info.minor' compared to integer (Python 4)," |
|
159 " compare 'sys.version_info' to tuple"), |
|
160 "M421": QCoreApplication.translate( |
|
161 "MiscellaneousChecker", |
|
162 "'sys.version[0]' referenced (Python 10), use 'sys.version_info'"), |
|
163 "M422": QCoreApplication.translate( |
|
164 "MiscellaneousChecker", |
|
165 "'sys.version' compared to string (Python 10)," |
|
166 " use 'sys.version_info'"), |
|
167 "M423": QCoreApplication.translate( |
|
168 "MiscellaneousChecker", |
|
169 "'sys.version[:1]' referenced (Python 10), use 'sys.version_info'"), |
|
170 |
|
171 "M501": QCoreApplication.translate( |
|
172 "MiscellaneousChecker", |
|
173 "Python does not support the unary prefix increment"), |
|
174 "M502": QCoreApplication.translate( |
|
175 "MiscellaneousChecker", |
|
176 "using .strip() with multi-character strings is misleading"), |
|
177 "M503": QCoreApplication.translate( |
|
178 "MiscellaneousChecker", |
|
179 "do not call assert False since python -O removes these calls"), |
|
180 "M504": QCoreApplication.translate( |
|
181 "MiscellaneousChecker", |
|
182 "'sys.maxint' is not defined in Python 3 - use 'sys.maxsize'"), |
|
183 "M505": QCoreApplication.translate( |
|
184 "MiscellaneousChecker", |
|
185 "'BaseException.message' has been deprecated as of Python 2.6 and is" |
|
186 " removed in Python 3 - use 'str(e)'"), |
|
187 "M506": QCoreApplication.translate( |
|
188 "MiscellaneousChecker", |
|
189 "assigning to 'os.environ' does not clear the environment -" |
|
190 " use 'os.environ.clear()'"), |
|
191 "M507": QCoreApplication.translate( |
|
192 "MiscellaneousChecker", |
|
193 "loop control variable {0} not used within the loop body -" |
|
194 " start the name with an underscore"), |
|
195 "M508": QCoreApplication.translate( |
|
196 "MiscellaneousChecker", |
|
197 "unncessary f-string"), |
|
198 "M509": QCoreApplication.translate( |
|
199 "MiscellaneousChecker", |
|
200 "cannot use 'self.__class__' as first argument of 'super()' call"), |
|
201 "M511": QCoreApplication.translate( |
|
202 "MiscellaneousChecker", |
|
203 """using 'hasattr(x, "__call__")' to test if 'x' is callable is""" |
|
204 """ unreliable"""), |
|
205 "M512": QCoreApplication.translate( |
|
206 "MiscellaneousChecker", |
|
207 "do not call getattr with a constant attribute value"), |
|
208 "M513": QCoreApplication.translate( |
|
209 "MiscellaneousChecker", |
|
210 "do not call setattr with a constant attribute value"), |
|
211 "M521": QCoreApplication.translate( |
|
212 "MiscellaneousChecker", |
|
213 "Python 3 does not include '.iter*' methods on dictionaries"), |
|
214 "M522": QCoreApplication.translate( |
|
215 "MiscellaneousChecker", |
|
216 "Python 3 does not include '.view*' methods on dictionaries"), |
|
217 "M523": QCoreApplication.translate( |
|
218 "MiscellaneousChecker", |
|
219 "'.next()' does not exist in Python 3"), |
|
220 "M524": QCoreApplication.translate( |
|
221 "MiscellaneousChecker", |
|
222 "'__metaclass__' does nothing on Python 3 -" |
|
223 " use 'class MyClass(BaseClass, metaclass=...)'"), |
|
224 |
|
225 "M601": QCoreApplication.translate( |
|
226 "MiscellaneousChecker", |
|
227 "found {0} formatter"), |
|
228 "M611": QCoreApplication.translate( |
|
229 "MiscellaneousChecker", |
|
230 "format string does contain unindexed parameters"), |
|
231 "M612": QCoreApplication.translate( |
|
232 "MiscellaneousChecker", |
|
233 "docstring does contain unindexed parameters"), |
|
234 "M613": QCoreApplication.translate( |
|
235 "MiscellaneousChecker", |
|
236 "other string does contain unindexed parameters"), |
|
237 "M621": QCoreApplication.translate( |
|
238 "MiscellaneousChecker", |
|
239 "format call uses too large index ({0})"), |
|
240 "M622": QCoreApplication.translate( |
|
241 "MiscellaneousChecker", |
|
242 "format call uses missing keyword ({0})"), |
|
243 "M623": QCoreApplication.translate( |
|
244 "MiscellaneousChecker", |
|
245 "format call uses keyword arguments but no named entries"), |
|
246 "M624": QCoreApplication.translate( |
|
247 "MiscellaneousChecker", |
|
248 "format call uses variable arguments but no numbered entries"), |
|
249 "M625": QCoreApplication.translate( |
|
250 "MiscellaneousChecker", |
|
251 "format call uses implicit and explicit indexes together"), |
|
252 "M631": QCoreApplication.translate( |
|
253 "MiscellaneousChecker", |
|
254 "format call provides unused index ({0})"), |
|
255 "M632": QCoreApplication.translate( |
|
256 "MiscellaneousChecker", |
|
257 "format call provides unused keyword ({0})"), |
|
258 "M651": QCoreApplication.translate( |
|
259 "MiscellaneousChecker", |
|
260 "logging statement uses string.format()"), |
|
261 "M652": QCoreApplication.translate( |
|
262 "MiscellaneousChecker", |
|
263 "logging statement uses '%'"), # __IGNORE_WARNING_M601__ |
|
264 "M653": QCoreApplication.translate( |
|
265 "MiscellaneousChecker", |
|
266 "logging statement uses '+'"), |
|
267 "M654": QCoreApplication.translate( |
|
268 "MiscellaneousChecker", |
|
269 "logging statement uses f-string"), |
|
270 "M655": QCoreApplication.translate( |
|
271 "MiscellaneousChecker", |
|
272 "logging statement uses 'warn' instead of 'warning'"), |
|
273 |
|
274 "M701": QCoreApplication.translate( |
|
275 "MiscellaneousChecker", |
|
276 "expected these __future__ imports: {0}; but only got: {1}"), |
|
277 "M702": QCoreApplication.translate( |
|
278 "MiscellaneousChecker", |
|
279 "expected these __future__ imports: {0}; but got none"), |
|
280 "M711": QCoreApplication.translate( |
|
281 "MiscellaneousChecker", |
|
282 "gettext import with alias _ found: {0}"), |
|
283 |
|
284 "M801": QCoreApplication.translate( |
|
285 "MiscellaneousChecker", |
|
286 "print statement found"), |
|
287 "M811": QCoreApplication.translate( |
|
288 "MiscellaneousChecker", |
|
289 "one element tuple found"), |
|
290 "M821": QCoreApplication.translate( |
|
291 "MiscellaneousChecker", |
|
292 "mutable default argument of type {0}"), |
|
293 "M822": QCoreApplication.translate( |
|
294 "MiscellaneousChecker", |
|
295 "mutable default argument of type {0}"), |
|
296 "M823": QCoreApplication.translate( |
|
297 "MiscellaneousChecker", |
|
298 "mutable default argument of function call '{0}'"), |
|
299 "M831": QCoreApplication.translate( |
|
300 "MiscellaneousChecker", |
|
301 "None should not be added at any return if function has no return" |
|
302 " value except None"), |
|
303 "M832": QCoreApplication.translate( |
|
304 "MiscellaneousChecker", |
|
305 "an explicit value at every return should be added if function has" |
|
306 " a return value except None"), |
|
307 "M833": QCoreApplication.translate( |
|
308 "MiscellaneousChecker", |
|
309 "an explicit return at the end of the function should be added if" |
|
310 " it has a return value except None"), |
|
311 "M834": QCoreApplication.translate( |
|
312 "MiscellaneousChecker", |
|
313 "a value should not be assigned to a variable if it will be used as a" |
|
314 " return value only"), |
|
315 "M841": QCoreApplication.translate( |
|
316 "MiscellaneousChecker", |
|
317 "prefer implied line continuation inside parentheses, " |
|
318 "brackets and braces as opposed to a backslash"), |
|
319 "M891": QCoreApplication.translate( |
|
320 "MiscellaneousChecker", |
|
321 "commented code lines should be removed"), |
|
322 |
|
323 "M901": QCoreApplication.translate( |
|
324 "MiscellaneousChecker", |
|
325 "{0}: {1}"), |
|
326 } |
|
327 |
|
328 _miscellaneousMessagesSampleArgs = { |
|
329 "M102": ["enc42"], |
|
330 "M131": ["list"], |
|
331 "M132": ["list"], |
|
332 "M188": ["sorted"], |
|
333 "M186": ["list"], |
|
334 "M191": ["list", "set"], |
|
335 "M192": ["list", "tuple"], |
|
336 "M193": ["tuple", "list"], |
|
337 "M197": ["tuple", "tuple"], |
|
338 "M198": ["list", "list"], |
|
339 "M201": ["bar", "foo"], |
|
340 "M507": ["x"], |
|
341 "M601": ["%s"], |
|
342 "M621": [5], |
|
343 "M622": ["foo"], |
|
344 "M631": [5], |
|
345 "M632": ["foo"], |
|
346 "M701": ["print_function, unicode_literals", "print_function"], |
|
347 "M702": ["print_function, unicode_literals"], |
|
348 "M711": ["lgettext"], |
|
349 "M821": ["Dict"], |
|
350 "M822": ["Call"], |
|
351 "M823": ["dict"], |
|
352 "M901": ["SyntaxError", "Invalid Syntax"], |
|
353 } |