|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2014 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing message translations for pyflakes warning messages. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 from PyQt5.QtCore import QCoreApplication |
|
13 |
|
14 __all__ = ["getTranslatedFlakesMessage"] |
|
15 |
|
16 _messages = { |
|
17 'F01': QCoreApplication.translate( |
|
18 'pyFlakes', |
|
19 '{0!r} imported but unused.'), |
|
20 'F02': QCoreApplication.translate( |
|
21 'pyFlakes', |
|
22 'Redefinition of unused {0!r} from line {1!r}.'), |
|
23 'F03': QCoreApplication.translate( |
|
24 'pyFlakes', |
|
25 'Import {0!r} from line {1!r} shadowed by loop variable.'), |
|
26 'F04': QCoreApplication.translate( |
|
27 'pyFlakes', |
|
28 "'from {0} import *' used; unable to detect undefined names."), |
|
29 'F05': QCoreApplication.translate( |
|
30 'pyFlakes', |
|
31 'Undefined name {0!r}.'), |
|
32 'F06': QCoreApplication.translate( |
|
33 'pyFlakes', |
|
34 'Undefined name {0!r} in __all__.'), |
|
35 'F07A': QCoreApplication.translate( |
|
36 'pyFlakes', |
|
37 "Local variable {0!r} (defined in enclosing scope on line {1!r})" |
|
38 " referenced before assignment."), |
|
39 'F07B': QCoreApplication.translate( |
|
40 'pyFlakes', |
|
41 "Local variable {0!r} (defined as a builtin)" |
|
42 " referenced before assignment."), |
|
43 'F08': QCoreApplication.translate( |
|
44 'pyFlakes', |
|
45 'Duplicate argument {0!r} in function definition.'), |
|
46 'F09': QCoreApplication.translate( |
|
47 'pyFlakes', |
|
48 'Redefinition of {0!r} from line {1!r}.'), |
|
49 'F10': QCoreApplication.translate( |
|
50 'pyFlakes', |
|
51 'from __future__ imports must occur at the beginning of the file'), |
|
52 'F11': QCoreApplication.translate( |
|
53 'pyFlakes', |
|
54 'Local variable {0!r} is assigned to but never used.'), |
|
55 'F12': QCoreApplication.translate( |
|
56 'pyFlakes', |
|
57 'List comprehension redefines {0!r} from line {1!r}.'), |
|
58 'F13': QCoreApplication.translate( |
|
59 'pyFlakes', |
|
60 'Syntax error detected in doctest.'), |
|
61 'F14': QCoreApplication.translate( |
|
62 'pyFlakes', |
|
63 "'return' with argument inside generator"), |
|
64 'F15': QCoreApplication.translate( |
|
65 'pyFlakes', |
|
66 "'return' outside function"), |
|
67 'F16': QCoreApplication.translate( |
|
68 'pyFlakes', |
|
69 "'from {0} import *' only allowed at module level"), |
|
70 'F17': QCoreApplication.translate( |
|
71 'pyFlakes', |
|
72 "{0!r} may be undefined, or defined from star imports: {1}"), |
|
73 'F18': QCoreApplication.translate( |
|
74 'pyFlakes', |
|
75 "Dictionary key {0!r} repeated with different values"), |
|
76 'F19': QCoreApplication.translate( |
|
77 'pyFlakes', |
|
78 "Dictionary key variable {0} repeated with different values"), |
|
79 'F20': QCoreApplication.translate( |
|
80 'pyFlakes', |
|
81 "Future feature {0} is not defined"), |
|
82 'F21': QCoreApplication.translate( |
|
83 'pyFlakes', |
|
84 "'yield' outside function"), |
|
85 'F22': QCoreApplication.translate( |
|
86 'pyFlakes', |
|
87 "'continue' not properly in loop"), |
|
88 'F23': QCoreApplication.translate( |
|
89 'pyFlakes', |
|
90 "'break' outside loop"), |
|
91 'F24': QCoreApplication.translate( |
|
92 'pyFlakes', |
|
93 "'continue' not supported inside 'finally' clause"), |
|
94 'F25': QCoreApplication.translate( |
|
95 'pyFlakes', |
|
96 "Default 'except:' must be last"), |
|
97 'F26': QCoreApplication.translate( |
|
98 'pyFlakes', |
|
99 "Two starred expressions in assignment"), |
|
100 'F27': QCoreApplication.translate( |
|
101 'pyFlakes', |
|
102 "Too many expressions in star-unpacking assignment"), |
|
103 'F28': QCoreApplication.translate( |
|
104 'pyFlakes', |
|
105 "Assertion is always true, perhaps remove parentheses?"), |
|
106 'F29': QCoreApplication.translate( |
|
107 'pyFlakes', |
|
108 "syntax error in forward annotation {0!r}"), |
|
109 'F30': QCoreApplication.translate( |
|
110 'pyFlakes', |
|
111 "'raise NotImplemented' should be 'raise NotImplementedError'"), |
|
112 'F31': QCoreApplication.translate( |
|
113 'pyFlakes', |
|
114 "syntax error in type comment {0!r}"), |
|
115 'F32': QCoreApplication.translate( |
|
116 'pyFlakes', |
|
117 "use of >> is invalid with print function"), |
|
118 'F33': QCoreApplication.translate( |
|
119 'pyFlakes', |
|
120 "use ==/!= to compare str, bytes, and int literals"), |
|
121 } |
|
122 |
|
123 |
|
124 def getTranslatedFlakesMessage(message_id, message_args): |
|
125 """ |
|
126 Module function to get a translated and formatted message for a |
|
127 given pyflakes message ID. |
|
128 |
|
129 @param message_id message ID (string) |
|
130 @param message_args arguments for a formatted message (list) |
|
131 @return translated and formatted message (string) |
|
132 """ |
|
133 if message_id in _messages: |
|
134 # Avoid leading "u" at Python2 unicode strings |
|
135 msg = _messages[message_id].replace("{0!r}", "'{0}'") |
|
136 msg = msg.replace("{1!r}", "'{1}'") |
|
137 return msg.format(*message_args) |
|
138 else: |
|
139 return QCoreApplication.translate( |
|
140 "pyFlakes", "no message defined for code '{0}'")\ |
|
141 .format(message_id) |