|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2014 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing message translations for the code style plugin messages. |
|
8 """ |
|
9 |
|
10 import re |
|
11 import contextlib |
|
12 |
|
13 from PyQt6.QtCore import QCoreApplication |
|
14 |
|
15 from .Annotations.translations import ( |
|
16 _annotationsMessages, _annotationsMessagesSampleArgs |
|
17 ) |
|
18 from .Complexity.translations import ( |
|
19 _complexityMessages, _complexityMessagesSampleArgs |
|
20 ) |
|
21 from .DocStyle.translations import ( |
|
22 _docStyleMessages, _docStyleMessagesSampleArgs |
|
23 ) |
|
24 from .Imports.translations import ( |
|
25 _importsMessages, _importsMessagesSampleArgs |
|
26 ) |
|
27 from .Miscellaneous.translations import ( |
|
28 _miscellaneousMessages, _miscellaneousMessagesSampleArgs |
|
29 ) |
|
30 from .Naming.translations import _namingStyleMessages |
|
31 from .PathLib.translations import _pathlibMessages |
|
32 from .Security.translations import ( |
|
33 _securityMessages, _securityMessagesSampleArgs |
|
34 ) |
|
35 from .Simplify.translations import ( |
|
36 _simplifyMessages, _simplifyMessagesSampleArgs |
|
37 ) |
|
38 |
|
39 ################################################################## |
|
40 ## pycodestyle error messages |
|
41 ################################################################## |
|
42 |
|
43 _pycodestyleErrorMessages = { |
|
44 "E101": QCoreApplication.translate( |
|
45 "pycodestyle", |
|
46 "indentation contains mixed spaces and tabs"), |
|
47 "E111": QCoreApplication.translate( |
|
48 "pycodestyle", |
|
49 "indentation is not a multiple of four"), |
|
50 "E112": QCoreApplication.translate( |
|
51 "pycodestyle", |
|
52 "expected an indented block"), |
|
53 "E113": QCoreApplication.translate( |
|
54 "pycodestyle", |
|
55 "unexpected indentation"), |
|
56 "E114": QCoreApplication.translate( |
|
57 "pycodestyle", |
|
58 "indentation is not a multiple of four (comment)"), |
|
59 "E115": QCoreApplication.translate( |
|
60 "pycodestyle", |
|
61 "expected an indented block (comment)"), |
|
62 "E116": QCoreApplication.translate( |
|
63 "pycodestyle", |
|
64 "unexpected indentation (comment)"), |
|
65 "E117": QCoreApplication.translate( |
|
66 "pycodestyle", |
|
67 "over-indented"), |
|
68 "E121": QCoreApplication.translate( |
|
69 "pycodestyle", |
|
70 "continuation line indentation is not a multiple of four"), |
|
71 "E122": QCoreApplication.translate( |
|
72 "pycodestyle", |
|
73 "continuation line missing indentation or outdented"), |
|
74 "E123": QCoreApplication.translate( |
|
75 "pycodestyle", |
|
76 "closing bracket does not match indentation of opening" |
|
77 " bracket's line"), |
|
78 "E124": QCoreApplication.translate( |
|
79 "pycodestyle", |
|
80 "closing bracket does not match visual indentation"), |
|
81 "E125": QCoreApplication.translate( |
|
82 "pycodestyle", |
|
83 "continuation line with same indent as next logical line"), |
|
84 "E126": QCoreApplication.translate( |
|
85 "pycodestyle", |
|
86 "continuation line over-indented for hanging indent"), |
|
87 "E127": QCoreApplication.translate( |
|
88 "pycodestyle", |
|
89 "continuation line over-indented for visual indent"), |
|
90 "E128": QCoreApplication.translate( |
|
91 "pycodestyle", |
|
92 "continuation line under-indented for visual indent"), |
|
93 "E129": QCoreApplication.translate( |
|
94 "pycodestyle", |
|
95 "visually indented line with same indent as next logical line"), |
|
96 "E131": QCoreApplication.translate( |
|
97 "pycodestyle", |
|
98 "continuation line unaligned for hanging indent"), |
|
99 "E133": QCoreApplication.translate( |
|
100 "pycodestyle", |
|
101 "closing bracket is missing indentation"), |
|
102 "E201": QCoreApplication.translate( |
|
103 "pycodestyle", |
|
104 "whitespace after '{0}'"), |
|
105 "E202": QCoreApplication.translate( |
|
106 "pycodestyle", |
|
107 "whitespace before '{0}'"), |
|
108 "E203": QCoreApplication.translate( |
|
109 "pycodestyle", |
|
110 "whitespace before '{0}'"), |
|
111 "E211": QCoreApplication.translate( |
|
112 "pycodestyle", |
|
113 "whitespace before '{0}'"), |
|
114 "E221": QCoreApplication.translate( |
|
115 "pycodestyle", |
|
116 "multiple spaces before operator"), |
|
117 "E222": QCoreApplication.translate( |
|
118 "pycodestyle", |
|
119 "multiple spaces after operator"), |
|
120 "E223": QCoreApplication.translate( |
|
121 "pycodestyle", |
|
122 "tab before operator"), |
|
123 "E224": QCoreApplication.translate( |
|
124 "pycodestyle", |
|
125 "tab after operator"), |
|
126 "E225": QCoreApplication.translate( |
|
127 "pycodestyle", |
|
128 "missing whitespace around operator"), |
|
129 "E226": QCoreApplication.translate( |
|
130 "pycodestyle", |
|
131 "missing whitespace around arithmetic operator"), |
|
132 "E227": QCoreApplication.translate( |
|
133 "pycodestyle", |
|
134 "missing whitespace around bitwise or shift operator"), |
|
135 "E228": QCoreApplication.translate( |
|
136 "pycodestyle", |
|
137 "missing whitespace around modulo operator"), |
|
138 "E231": QCoreApplication.translate( |
|
139 "pycodestyle", |
|
140 "missing whitespace after '{0}'"), |
|
141 "E241": QCoreApplication.translate( |
|
142 "pycodestyle", |
|
143 "multiple spaces after '{0}'"), |
|
144 "E242": QCoreApplication.translate( |
|
145 "pycodestyle", |
|
146 "tab after '{0}'"), |
|
147 "E251": QCoreApplication.translate( |
|
148 "pycodestyle", |
|
149 "unexpected spaces around keyword / parameter equals"), |
|
150 "E252": QCoreApplication.translate( |
|
151 "pycodestyle", |
|
152 "missing whitespace around parameter equals"), |
|
153 "E261": QCoreApplication.translate( |
|
154 "pycodestyle", |
|
155 "at least two spaces before inline comment"), |
|
156 "E262": QCoreApplication.translate( |
|
157 "pycodestyle", |
|
158 "inline comment should start with '# '"), |
|
159 "E265": QCoreApplication.translate( |
|
160 "pycodestyle", |
|
161 "block comment should start with '# '"), |
|
162 "E266": QCoreApplication.translate( |
|
163 "pycodestyle", |
|
164 "too many leading '#' for block comment"), |
|
165 "E271": QCoreApplication.translate( |
|
166 "pycodestyle", |
|
167 "multiple spaces after keyword"), |
|
168 "E272": QCoreApplication.translate( |
|
169 "pycodestyle", |
|
170 "multiple spaces before keyword"), |
|
171 "E273": QCoreApplication.translate( |
|
172 "pycodestyle", |
|
173 "tab after keyword"), |
|
174 "E274": QCoreApplication.translate( |
|
175 "pycodestyle", |
|
176 "tab before keyword"), |
|
177 "E275": QCoreApplication.translate( |
|
178 "pycodestyle", |
|
179 "missing whitespace after keyword"), |
|
180 "E301": QCoreApplication.translate( |
|
181 "pycodestyle", |
|
182 "expected {0} blank lines, found {1}"), |
|
183 "E302": QCoreApplication.translate( |
|
184 "pycodestyle", |
|
185 "expected {0} blank lines, found {1}"), |
|
186 "E303": QCoreApplication.translate( |
|
187 "pycodestyle", |
|
188 "too many blank lines ({0}), expected {1}"), |
|
189 "E304": QCoreApplication.translate( |
|
190 "pycodestyle", |
|
191 "blank lines found after function decorator"), |
|
192 "E305": QCoreApplication.translate( |
|
193 "pycodestyle", |
|
194 "expected {0} blank lines after class or function definition," |
|
195 " found {1}"), |
|
196 "E306": QCoreApplication.translate( |
|
197 "pycodestyle", |
|
198 "expected {0} blank lines before a nested definition, found {1}"), |
|
199 "E307": QCoreApplication.translate( |
|
200 "pycodestyle", |
|
201 "too many blank lines ({0}) before a nested definition, expected {1}"), |
|
202 "E308": QCoreApplication.translate( |
|
203 "pycodestyle", |
|
204 "too many blank lines ({0})"), |
|
205 "E401": QCoreApplication.translate( |
|
206 "pycodestyle", |
|
207 "multiple imports on one line"), |
|
208 "E402": QCoreApplication.translate( |
|
209 "pycodestyle", |
|
210 "module level import not at top of file"), |
|
211 "E501": QCoreApplication.translate( |
|
212 "pycodestyle", |
|
213 "line too long ({0} > {1} characters)"), |
|
214 "E502": QCoreApplication.translate( |
|
215 "pycodestyle", |
|
216 "the backslash is redundant between brackets"), |
|
217 "E701": QCoreApplication.translate( |
|
218 "pycodestyle", |
|
219 "multiple statements on one line (colon)"), |
|
220 "E702": QCoreApplication.translate( |
|
221 "pycodestyle", |
|
222 "multiple statements on one line (semicolon)"), |
|
223 "E703": QCoreApplication.translate( |
|
224 "pycodestyle", |
|
225 "statement ends with a semicolon"), |
|
226 "E704": QCoreApplication.translate( |
|
227 "pycodestyle", |
|
228 "multiple statements on one line (def)"), |
|
229 "E711": QCoreApplication.translate( |
|
230 "pycodestyle", |
|
231 "comparison to {0} should be {1}"), |
|
232 "E712": QCoreApplication.translate( |
|
233 "pycodestyle", |
|
234 "comparison to {0} should be {1}"), |
|
235 "E713": QCoreApplication.translate( |
|
236 "pycodestyle", |
|
237 "test for membership should be 'not in'"), |
|
238 "E714": QCoreApplication.translate( |
|
239 "pycodestyle", |
|
240 "test for object identity should be 'is not'"), |
|
241 "E721": QCoreApplication.translate( |
|
242 "pycodestyle", |
|
243 "do not compare types, use 'isinstance()'"), |
|
244 "E722": QCoreApplication.translate( |
|
245 "pycodestyle", |
|
246 "do not use bare except"), |
|
247 "E731": QCoreApplication.translate( |
|
248 "pycodestyle", |
|
249 "do not assign a lambda expression, use a def"), |
|
250 "E741": QCoreApplication.translate( |
|
251 "pycodestyle", |
|
252 "ambiguous variable name '{0}'"), |
|
253 "E742": QCoreApplication.translate( |
|
254 "pycodestyle", |
|
255 "ambiguous class definition '{0}'"), |
|
256 "E743": QCoreApplication.translate( |
|
257 "pycodestyle", |
|
258 "ambiguous function definition '{0}'"), |
|
259 "E901": QCoreApplication.translate( |
|
260 "pycodestyle", |
|
261 "{0}: {1}"), |
|
262 "E902": QCoreApplication.translate( |
|
263 "pycodestyle", |
|
264 "{0}"), |
|
265 } |
|
266 |
|
267 ################################################################## |
|
268 ## pycodestyle warning messages |
|
269 ################################################################## |
|
270 |
|
271 _pycodestyleWarningMessages = { |
|
272 "W191": QCoreApplication.translate( |
|
273 "pycodestyle", |
|
274 "indentation contains tabs"), |
|
275 "W291": QCoreApplication.translate( |
|
276 "pycodestyle", |
|
277 "trailing whitespace"), |
|
278 "W292": QCoreApplication.translate( |
|
279 "pycodestyle", |
|
280 "no newline at end of file"), |
|
281 "W293": QCoreApplication.translate( |
|
282 "pycodestyle", |
|
283 "blank line contains whitespace"), |
|
284 "W391": QCoreApplication.translate( |
|
285 "pycodestyle", |
|
286 "blank line at end of file"), |
|
287 "W503": QCoreApplication.translate( |
|
288 "pycodestyle", |
|
289 "line break before binary operator"), |
|
290 "W504": QCoreApplication.translate( |
|
291 "pycodestyle", |
|
292 "line break after binary operator"), |
|
293 "W505": QCoreApplication.translate( |
|
294 "pycodestyle", |
|
295 "doc line too long ({0} > {1} characters)"), |
|
296 "W601": QCoreApplication.translate( |
|
297 "pycodestyle", |
|
298 ".has_key() is deprecated, use 'in'"), |
|
299 "W602": QCoreApplication.translate( |
|
300 "pycodestyle", |
|
301 "deprecated form of raising exception"), |
|
302 "W603": QCoreApplication.translate( |
|
303 "pycodestyle", |
|
304 "'<>' is deprecated, use '!='"), |
|
305 "W604": QCoreApplication.translate( |
|
306 "pycodestyle", |
|
307 "backticks are deprecated, use 'repr()'"), |
|
308 "W605": QCoreApplication.translate( |
|
309 "pycodestyle", |
|
310 "invalid escape sequence '\\{0}'"), |
|
311 "W606": QCoreApplication.translate( |
|
312 "pycodestyle", |
|
313 "'async' and 'await' are reserved keywords starting with Python 3.7"), |
|
314 } |
|
315 |
|
316 ################################################################## |
|
317 ## CodeStyleFixer messages |
|
318 ################################################################## |
|
319 |
|
320 _fixMessages = { |
|
321 "FIXD111": QCoreApplication.translate( |
|
322 'CodeStyleFixer', |
|
323 "Triple single quotes converted to triple double quotes."), |
|
324 'FIXD112': QCoreApplication.translate( |
|
325 'CodeStyleFixer', |
|
326 'Introductory quotes corrected to be {0}"""'), |
|
327 "FIXD121": QCoreApplication.translate( |
|
328 'CodeStyleFixer', |
|
329 "Single line docstring put on one line."), |
|
330 "FIXD131": QCoreApplication.translate( |
|
331 'CodeStyleFixer', |
|
332 "Period added to summary line."), |
|
333 "FIXD141": QCoreApplication.translate( |
|
334 'CodeStyleFixer', |
|
335 "Blank line before function/method docstring removed."), |
|
336 "FIXD142": QCoreApplication.translate( |
|
337 'CodeStyleFixer', |
|
338 "Blank line inserted before class docstring."), |
|
339 "FIXD143": QCoreApplication.translate( |
|
340 'CodeStyleFixer', |
|
341 "Blank line inserted after class docstring."), |
|
342 "FIXD144": QCoreApplication.translate( |
|
343 'CodeStyleFixer', |
|
344 "Blank line inserted after docstring summary."), |
|
345 "FIXD145": QCoreApplication.translate( |
|
346 'CodeStyleFixer', |
|
347 "Blank line inserted after last paragraph of docstring."), |
|
348 "FIXD221": QCoreApplication.translate( |
|
349 'CodeStyleFixer', |
|
350 "Leading quotes put on separate line."), |
|
351 "FIXD222": QCoreApplication.translate( |
|
352 'CodeStyleFixer', |
|
353 "Trailing quotes put on separate line."), |
|
354 "FIXD242": QCoreApplication.translate( |
|
355 'CodeStyleFixer', |
|
356 "Blank line before class docstring removed."), |
|
357 "FIXD244": QCoreApplication.translate( |
|
358 'CodeStyleFixer', |
|
359 "Blank line before function/method docstring removed."), |
|
360 "FIXD243": QCoreApplication.translate( |
|
361 'CodeStyleFixer', |
|
362 "Blank line after class docstring removed."), |
|
363 "FIXD245": QCoreApplication.translate( |
|
364 'CodeStyleFixer', |
|
365 "Blank line after function/method docstring removed."), |
|
366 "FIXD247": QCoreApplication.translate( |
|
367 'CodeStyleFixer', |
|
368 "Blank line after last paragraph removed."), |
|
369 "FIXE101": QCoreApplication.translate( |
|
370 'CodeStyleFixer', |
|
371 "Tab converted to 4 spaces."), |
|
372 "FIXE111": QCoreApplication.translate( |
|
373 'CodeStyleFixer', |
|
374 "Indentation adjusted to be a multiple of four."), |
|
375 "FIXE121": QCoreApplication.translate( |
|
376 'CodeStyleFixer', |
|
377 "Indentation of continuation line corrected."), |
|
378 "FIXE124": QCoreApplication.translate( |
|
379 'CodeStyleFixer', |
|
380 "Indentation of closing bracket corrected."), |
|
381 "FIXE122": QCoreApplication.translate( |
|
382 'CodeStyleFixer', |
|
383 "Missing indentation of continuation line corrected."), |
|
384 "FIXE123": QCoreApplication.translate( |
|
385 'CodeStyleFixer', |
|
386 "Closing bracket aligned to opening bracket."), |
|
387 "FIXE125": QCoreApplication.translate( |
|
388 'CodeStyleFixer', |
|
389 "Indentation level changed."), |
|
390 "FIXE126": QCoreApplication.translate( |
|
391 'CodeStyleFixer', |
|
392 "Indentation level of hanging indentation changed."), |
|
393 "FIXE127": QCoreApplication.translate( |
|
394 'CodeStyleFixer', |
|
395 "Visual indentation corrected."), |
|
396 "FIXE201": QCoreApplication.translate( |
|
397 'CodeStyleFixer', |
|
398 "Extraneous whitespace removed."), |
|
399 "FIXE225": QCoreApplication.translate( |
|
400 'CodeStyleFixer', |
|
401 "Missing whitespace added."), |
|
402 "FIXE221": QCoreApplication.translate( |
|
403 'CodeStyleFixer', |
|
404 "Extraneous whitespace removed."), |
|
405 "FIXE231": QCoreApplication.translate( |
|
406 'CodeStyleFixer', |
|
407 "Missing whitespace added."), |
|
408 "FIXE251": QCoreApplication.translate( |
|
409 'CodeStyleFixer', |
|
410 "Extraneous whitespace removed."), |
|
411 "FIXE261": QCoreApplication.translate( |
|
412 'CodeStyleFixer', |
|
413 "Whitespace around comment sign corrected."), |
|
414 |
|
415 "FIXE302+": lambda n=1: QCoreApplication.translate( |
|
416 'CodeStyleFixer', |
|
417 "%n blank line(s) inserted.", '', n), |
|
418 "FIXE302-": lambda n=1: QCoreApplication.translate( |
|
419 'CodeStyleFixer', |
|
420 "%n superfluous lines removed", '', n), |
|
421 |
|
422 "FIXE303": QCoreApplication.translate( |
|
423 'CodeStyleFixer', |
|
424 "Superfluous blank lines removed."), |
|
425 "FIXE304": QCoreApplication.translate( |
|
426 'CodeStyleFixer', |
|
427 "Superfluous blank lines after function decorator removed."), |
|
428 "FIXE401": QCoreApplication.translate( |
|
429 'CodeStyleFixer', |
|
430 "Imports were put on separate lines."), |
|
431 "FIXE501": QCoreApplication.translate( |
|
432 'CodeStyleFixer', |
|
433 "Long lines have been shortened."), |
|
434 "FIXE502": QCoreApplication.translate( |
|
435 'CodeStyleFixer', |
|
436 "Redundant backslash in brackets removed."), |
|
437 "FIXE701": QCoreApplication.translate( |
|
438 'CodeStyleFixer', |
|
439 "Compound statement corrected."), |
|
440 "FIXE702": QCoreApplication.translate( |
|
441 'CodeStyleFixer', |
|
442 "Compound statement corrected."), |
|
443 "FIXE711": QCoreApplication.translate( |
|
444 'CodeStyleFixer', |
|
445 "Comparison to None/True/False corrected."), |
|
446 "FIXN804": QCoreApplication.translate( |
|
447 'CodeStyleFixer', |
|
448 "'{0}' argument added."), |
|
449 "FIXN806": QCoreApplication.translate( |
|
450 'CodeStyleFixer', |
|
451 "'{0}' argument removed."), |
|
452 "FIXW291": QCoreApplication.translate( |
|
453 'CodeStyleFixer', |
|
454 "Whitespace stripped from end of line."), |
|
455 "FIXW292": QCoreApplication.translate( |
|
456 'CodeStyleFixer', |
|
457 "newline added to end of file."), |
|
458 "FIXW391": QCoreApplication.translate( |
|
459 'CodeStyleFixer', |
|
460 "Superfluous trailing blank lines removed from end of file."), |
|
461 "FIXW603": QCoreApplication.translate( |
|
462 'CodeStyleFixer', |
|
463 "'<>' replaced by '!='."), |
|
464 |
|
465 "FIXWRITE_ERROR": QCoreApplication.translate( |
|
466 'CodeStyleFixer', |
|
467 "Could not save the file! Skipping it. Reason: {0}"), |
|
468 } |
|
469 |
|
470 _pycodestyleErrorMessagesSampleArgs = { |
|
471 "E201": ["([{"], |
|
472 "E202": ["}])"], |
|
473 "E203": [",;:"], |
|
474 "E211": ["(["], |
|
475 "E231": [",;:"], |
|
476 "E241": [",;:"], |
|
477 "E242": [",;:"], |
|
478 "E301": [1, 0], |
|
479 "E302": [2, 1], |
|
480 "E303": [3, 2], |
|
481 "E305": [2, 1], |
|
482 "E306": [1, 0], |
|
483 "E307": [3, 1], |
|
484 "E308": [3], |
|
485 "E501": [95, 88], |
|
486 "E711": ["None", "'if cond is None:'"], |
|
487 "E712": ["True", "'if cond is True:' or 'if cond:'"], |
|
488 "E741": ["l"], |
|
489 "E742": ["l"], |
|
490 "E743": ["l"], |
|
491 "E901": ["SyntaxError", "Invalid Syntax"], |
|
492 "E902": ["OSError"], |
|
493 } |
|
494 |
|
495 _pycodestyleWarningMessagesSampleArgs = { |
|
496 "W505": [80, 72], |
|
497 "W605": ["A"], |
|
498 } |
|
499 |
|
500 _fixMessagesSampleArgs = { |
|
501 "FIXWRITE_ERROR": ["OSError"], |
|
502 } |
|
503 |
|
504 messageCatalogs = { |
|
505 "A": _annotationsMessages, |
|
506 "C": _complexityMessages, |
|
507 "D": _docStyleMessages, |
|
508 "E": _pycodestyleErrorMessages, |
|
509 "I": _importsMessages, |
|
510 "M": _miscellaneousMessages, |
|
511 "N": _namingStyleMessages, |
|
512 "P": _pathlibMessages, |
|
513 "S": _securityMessages, |
|
514 "W": _pycodestyleWarningMessages, |
|
515 "Y": _simplifyMessages, |
|
516 |
|
517 "FIX": _fixMessages, |
|
518 } |
|
519 |
|
520 messageSampleArgsCatalog = { |
|
521 "A": _annotationsMessagesSampleArgs, |
|
522 "C": _complexityMessagesSampleArgs, |
|
523 "D": _docStyleMessagesSampleArgs, |
|
524 "E": _pycodestyleErrorMessagesSampleArgs, |
|
525 "I": _importsMessagesSampleArgs, |
|
526 "M": _miscellaneousMessagesSampleArgs, |
|
527 "S": _securityMessagesSampleArgs, |
|
528 "W": _pycodestyleWarningMessagesSampleArgs, |
|
529 "Y": _simplifyMessagesSampleArgs, |
|
530 |
|
531 "FIX": _fixMessagesSampleArgs, |
|
532 } |
|
533 |
|
534 messageCategoryRe = re.compile(r"([A-Z]{1,3}).+") |
|
535 |
|
536 |
|
537 def getTranslatedMessage(messageCode, messageArgs, example=False): |
|
538 """ |
|
539 Module function to get a translated and formatted message for a |
|
540 given message ID. |
|
541 |
|
542 @param messageCode the message code |
|
543 @type str |
|
544 @param messageArgs list of arguments or a single integer value to format |
|
545 the message |
|
546 @type list or int |
|
547 @param example flag indicating a translated message filled with example |
|
548 data is requested (messageArgs is ignored if given) |
|
549 @type bool |
|
550 @return translated and formatted message |
|
551 @rtype str |
|
552 """ |
|
553 match = messageCategoryRe.match(messageCode) |
|
554 if match: |
|
555 # the message code is OK |
|
556 messageCategory = match.group(1) |
|
557 |
|
558 if example: |
|
559 try: |
|
560 argsCatalog = messageSampleArgsCatalog[messageCategory] |
|
561 try: |
|
562 args = argsCatalog[messageCode] |
|
563 except KeyError: |
|
564 args = None |
|
565 except KeyError: |
|
566 args = None |
|
567 else: |
|
568 args = messageArgs |
|
569 |
|
570 with contextlib.suppress(KeyError): |
|
571 catalog = messageCatalogs[messageCategory] |
|
572 with contextlib.suppress(KeyError): |
|
573 message = catalog[messageCode] |
|
574 if args is None: |
|
575 return message |
|
576 elif isinstance(args, int): |
|
577 # Retranslate with correct plural form |
|
578 return message(args) |
|
579 else: |
|
580 return message.format(*args) |
|
581 |
|
582 if example: |
|
583 return None |
|
584 else: |
|
585 return QCoreApplication.translate( |
|
586 "CodeStyleChecker", |
|
587 "No message defined for code '{0}'." |
|
588 ).format(messageCode) |
|
589 |
|
590 |
|
591 def getMessageCodes(): |
|
592 """ |
|
593 Module function to get a list of known message codes. |
|
594 |
|
595 @return list of known message codes |
|
596 @rtype set of str |
|
597 """ |
|
598 knownCodes = [] |
|
599 for catalog in messageCatalogs.values(): |
|
600 knownCodes += list(catalog.keys()) |
|
601 return {c.split(".", 1)[0] for c in knownCodes} |
|
602 |
|
603 # |
|
604 # eflag: noqa = M201 |