5 # Original (c) 2005 Divmod, Inc. See LICENSE file for details |
5 # Original (c) 2005 Divmod, Inc. See LICENSE file for details |
6 # |
6 # |
7 # This module is based on pyflakes for Python2 but was heavily hacked to |
7 # This module is based on pyflakes for Python2 but was heavily hacked to |
8 # work with Python3 and Qt (translatable messages) |
8 # work with Python3 and Qt (translatable messages) |
9 |
9 |
10 from PyQt4.QtCore import QCoreApplication |
10 |
|
11 def QT_TRANSLATE_NOOP(mod, txt): |
|
12 """ |
|
13 Function to tell 'lupdate' which strings to keep for translation. |
|
14 |
|
15 @param mod module name |
|
16 @param txt translatable string |
|
17 @return the untranslated! string |
|
18 """ |
|
19 return txt |
11 |
20 |
12 |
21 |
13 class Message(object): |
22 class Message(object): |
14 """ |
23 """ |
15 Class defining the base for all specific message classes. |
24 Class defining the base for all specific message classes. |
41 Public method to get the individual message data elements. |
50 Public method to get the individual message data elements. |
42 |
51 |
43 @return tuple containing file name, line number and message |
52 @return tuple containing file name, line number and message |
44 (string, integer, string) |
53 (string, integer, string) |
45 """ |
54 """ |
46 return (self.filename, self.lineno, self.message.format(*self.message_args)) |
55 return (self.filename, self.lineno, self.message, self.message_args) |
47 |
56 |
48 |
57 |
49 class UnusedImport(Message): |
58 class UnusedImport(Message): |
50 """ |
59 """ |
51 Class defining the "Unused Import" message. |
60 Class defining the "Unused Import" message. |
52 """ |
61 """ |
53 message = QCoreApplication.translate('py3Flakes', |
62 message = QT_TRANSLATE_NOOP('py3Flakes', |
54 '{0!r} imported but unused.') |
63 '{0!r} imported but unused.') |
55 |
64 |
56 def __init__(self, filename, lineno, name): |
65 def __init__(self, filename, lineno, name): |
57 """ |
66 """ |
58 Constructor |
67 Constructor |
67 |
76 |
68 class RedefinedWhileUnused(Message): |
77 class RedefinedWhileUnused(Message): |
69 """ |
78 """ |
70 Class defining the "Redefined While Unused" message. |
79 Class defining the "Redefined While Unused" message. |
71 """ |
80 """ |
72 message = QCoreApplication.translate('py3Flakes', |
81 message = QT_TRANSLATE_NOOP('py3Flakes', |
73 'Redefinition of unused {0!r} from line {1!r}.') |
82 'Redefinition of unused {0!r} from line {1!r}.') |
74 |
83 |
75 def __init__(self, filename, lineno, name, orig_lineno): |
84 def __init__(self, filename, lineno, name, orig_lineno): |
76 """ |
85 """ |
77 Constructor |
86 Constructor |
78 |
87 |
79 @param filename name of the file (string) |
88 @param filename name of the file (string) |
87 |
96 |
88 class ImportShadowedByLoopVar(Message): |
97 class ImportShadowedByLoopVar(Message): |
89 """ |
98 """ |
90 Class defining the "Import Shadowed By Loop Var" message. |
99 Class defining the "Import Shadowed By Loop Var" message. |
91 """ |
100 """ |
92 message = QCoreApplication.translate('py3Flakes', |
101 message = QT_TRANSLATE_NOOP('py3Flakes', |
93 'Import {0!r} from line {1!r} shadowed by loop variable.') |
102 'Import {0!r} from line {1!r} shadowed by loop variable.') |
94 |
103 |
95 def __init__(self, filename, lineno, name, orig_lineno): |
104 def __init__(self, filename, lineno, name, orig_lineno): |
96 """ |
105 """ |
97 Constructor |
106 Constructor |
107 |
116 |
108 class ImportStarUsed(Message): |
117 class ImportStarUsed(Message): |
109 """ |
118 """ |
110 Class defining the "Import Star Used" message. |
119 Class defining the "Import Star Used" message. |
111 """ |
120 """ |
112 message = QCoreApplication.translate('py3Flakes', |
121 message = QT_TRANSLATE_NOOP('py3Flakes', |
113 "'from {0} import *' used; unable to detect undefined names.") |
122 "'from {0} import *' used; unable to detect undefined names.") |
114 |
123 |
115 def __init__(self, filename, lineno, modname): |
124 def __init__(self, filename, lineno, modname): |
116 """ |
125 """ |
117 Constructor |
126 Constructor |
126 |
135 |
127 class UndefinedName(Message): |
136 class UndefinedName(Message): |
128 """ |
137 """ |
129 Class defining the "Undefined Name" message. |
138 Class defining the "Undefined Name" message. |
130 """ |
139 """ |
131 message = QCoreApplication.translate('py3Flakes', 'Undefined name {0!r}.') |
140 message = QT_TRANSLATE_NOOP('py3Flakes', 'Undefined name {0!r}.') |
132 |
141 |
133 def __init__(self, filename, lineno, name): |
142 def __init__(self, filename, lineno, name): |
134 """ |
143 """ |
135 Constructor |
144 Constructor |
136 |
145 |
144 |
153 |
145 class UndefinedExport(Message): |
154 class UndefinedExport(Message): |
146 """ |
155 """ |
147 Class defining the "Undefined Export" message. |
156 Class defining the "Undefined Export" message. |
148 """ |
157 """ |
149 message = QCoreApplication.translate('py3Flakes', 'Undefined name {0!r} in __all__.') |
158 message = QT_TRANSLATE_NOOP('py3Flakes', |
|
159 'Undefined name {0!r} in __all__.') |
150 |
160 |
151 def __init__(self, filename, lineno, name): |
161 def __init__(self, filename, lineno, name): |
152 """ |
162 """ |
153 Constructor |
163 Constructor |
154 |
164 |
162 |
172 |
163 class UndefinedLocal(Message): |
173 class UndefinedLocal(Message): |
164 """ |
174 """ |
165 Class defining the "Undefined Local Variable" message. |
175 Class defining the "Undefined Local Variable" message. |
166 """ |
176 """ |
167 message = QCoreApplication.translate('py3Flakes', |
177 message = QT_TRANSLATE_NOOP('py3Flakes', |
168 "Local variable {0!r} (defined in enclosing scope on line {1!r})" |
178 "Local variable {0!r} (defined in enclosing scope on line {1!r})" \ |
169 " referenced before assignment.") |
179 " referenced before assignment.") |
170 |
180 |
171 def __init__(self, filename, lineno, name, orig_lineno): |
181 def __init__(self, filename, lineno, name, orig_lineno): |
172 """ |
182 """ |
173 Constructor |
183 Constructor |
174 |
184 |
183 |
193 |
184 class DuplicateArgument(Message): |
194 class DuplicateArgument(Message): |
185 """ |
195 """ |
186 Class defining the "Duplicate Argument" message. |
196 Class defining the "Duplicate Argument" message. |
187 """ |
197 """ |
188 message = QCoreApplication.translate('py3Flakes', |
198 message = QT_TRANSLATE_NOOP('py3Flakes', |
189 'Duplicate argument {0!r} in function definition.') |
199 'Duplicate argument {0!r} in function definition.') |
190 |
200 |
191 def __init__(self, filename, lineno, name): |
201 def __init__(self, filename, lineno, name): |
192 """ |
202 """ |
193 Constructor |
203 Constructor |
202 |
212 |
203 class RedefinedFunction(Message): |
213 class RedefinedFunction(Message): |
204 """ |
214 """ |
205 Class defining the "Redefined Function" message. |
215 Class defining the "Redefined Function" message. |
206 """ |
216 """ |
207 message = QCoreApplication.translate('py3Flakes', |
217 message = QT_TRANSLATE_NOOP('py3Flakes', |
208 'Redefinition of function {0!r} from line {1!r}.') |
218 'Redefinition of function {0!r} from line {1!r}.') |
209 |
219 |
210 def __init__(self, filename, lineno, name, orig_lineno): |
220 def __init__(self, filename, lineno, name, orig_lineno): |
211 """ |
221 """ |
212 Constructor |
222 Constructor |
222 |
232 |
223 class LateFutureImport(Message): |
233 class LateFutureImport(Message): |
224 """ |
234 """ |
225 Class defining the "Late Future Import" message. |
235 Class defining the "Late Future Import" message. |
226 """ |
236 """ |
227 message = QCoreApplication.translate('py3Flakes', |
237 message = QT_TRANSLATE_NOOP('py3Flakes', |
228 'Future import(s) {0!r} after other statements.') |
238 'Future import(s) {0!r} after other statements.') |
229 |
239 |
230 def __init__(self, filename, lineno, names): |
240 def __init__(self, filename, lineno, names): |
231 """ |
241 """ |
232 Constructor |
242 Constructor |
244 Class defining the "Unused Variable" message. |
254 Class defining the "Unused Variable" message. |
245 |
255 |
246 Indicates that a variable has been explicitly assigned to but not actually |
256 Indicates that a variable has been explicitly assigned to but not actually |
247 used. |
257 used. |
248 """ |
258 """ |
249 message = QCoreApplication.translate('py3Flakes', |
259 message = QT_TRANSLATE_NOOP('py3Flakes', |
250 'Local variable {0!r} is assigned to but never used.') |
260 'Local variable {0!r} is assigned to but never used.') |
251 |
261 |
252 def __init__(self, filename, lineno, name): |
262 def __init__(self, filename, lineno, name): |
253 """ |
263 """ |
254 Constructor |
264 Constructor |