|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2010 - 2014 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 # Original (c) 2005 Divmod, Inc. See __init__.py file for details |
|
6 # |
|
7 # This module is based on pyflakes but was heavily hacked to |
|
8 # work within Eric5 and Qt (translatable messages) |
|
9 |
|
10 """ |
|
11 Provide the class Message and its subclasses. |
|
12 """ |
|
13 |
|
14 # Tell 'lupdate' which strings to keep for translation. |
|
15 QT_TRANSLATE_NOOP = lambda mod, txt: txt |
|
16 |
|
17 |
|
18 class Message(object): |
|
19 """ |
|
20 Class defining the base for all specific message classes. |
|
21 """ |
|
22 message = '' |
|
23 message_args = () |
|
24 |
|
25 def __init__(self, filename, loc): |
|
26 """ |
|
27 Constructor |
|
28 |
|
29 @param filename name of the file (string) |
|
30 @param loc location of warning (object) |
|
31 """ |
|
32 self.filename = filename |
|
33 self.lineno = loc.lineno |
|
34 self.col = getattr(loc, 'col_offset', 0) |
|
35 |
|
36 def __str__(self): |
|
37 """ |
|
38 Special method return a string representation of the instance object. |
|
39 |
|
40 @return string representation of the object (string) |
|
41 """ |
|
42 return '%s:%s: %s' % (self.filename, self.lineno, |
|
43 self.message % self.message_args) |
|
44 |
|
45 def getMessageData(self): |
|
46 """ |
|
47 Public method to get the individual message data elements. |
|
48 |
|
49 @return tuple containing file name, line number and message |
|
50 (string, integer, string) |
|
51 """ |
|
52 return (self.filename, self.lineno, self.col, self.message, |
|
53 self.message_args) |
|
54 |
|
55 |
|
56 class UnusedImport(Message): |
|
57 """ |
|
58 Class defining the "Unused Import" message. |
|
59 """ |
|
60 message = QT_TRANSLATE_NOOP( |
|
61 'py3Flakes', |
|
62 '{0!r} imported but unused.') |
|
63 |
|
64 def __init__(self, filename, loc, name): |
|
65 """ |
|
66 Constructor |
|
67 |
|
68 @param filename name of the file (string) |
|
69 @param loc location of warning (object) |
|
70 @param name name of the unused import (string) |
|
71 """ |
|
72 Message.__init__(self, filename, loc) |
|
73 self.message_args = (name,) |
|
74 |
|
75 |
|
76 class RedefinedWhileUnused(Message): |
|
77 """ |
|
78 Class defining the "Redefined While Unused" message. |
|
79 """ |
|
80 message = QT_TRANSLATE_NOOP( |
|
81 'py3Flakes', |
|
82 'Redefinition of unused {0!r} from line {1!r}.') |
|
83 |
|
84 def __init__(self, filename, loc, name, orig_loc): |
|
85 """ |
|
86 Constructor |
|
87 |
|
88 @param filename name of the file (string) |
|
89 @param loc location of warning (object) |
|
90 @param name name of the redefined object (string) |
|
91 @param orig_loc location of the original definition (object) |
|
92 """ |
|
93 Message.__init__(self, filename, loc) |
|
94 self.message_args = (name, orig_loc.lineno) |
|
95 |
|
96 |
|
97 class RedefinedInListComp(Message): |
|
98 """ |
|
99 Class defining the list comprehension redefinition. |
|
100 """ |
|
101 message = QT_TRANSLATE_NOOP( |
|
102 'py3Flakes', |
|
103 'List comprehension redefines {0!r} from line {1!r}.') |
|
104 |
|
105 def __init__(self, filename, loc, name, orig_loc): |
|
106 """ |
|
107 Constructor |
|
108 |
|
109 @param filename name of the file (string) |
|
110 @param loc location of warning (object) |
|
111 @param name name of the redefined object (string) |
|
112 @param orig_loc location of the original definition (object) |
|
113 """ |
|
114 Message.__init__(self, filename, loc) |
|
115 self.message_args = (name, orig_loc.lineno) |
|
116 |
|
117 |
|
118 class ImportShadowedByLoopVar(Message): |
|
119 """ |
|
120 Class defining the "Import Shadowed By Loop Var" message. |
|
121 """ |
|
122 message = QT_TRANSLATE_NOOP( |
|
123 'py3Flakes', |
|
124 'Import {0!r} from line {1!r} shadowed by loop variable.') |
|
125 |
|
126 def __init__(self, filename, loc, name, orig_loc): |
|
127 """ |
|
128 Constructor |
|
129 |
|
130 @param filename name of the file (string) |
|
131 @param loc location of warning (object) |
|
132 @param name name of the shadowed import (string) |
|
133 @param orig_loc location of the import (object) |
|
134 """ |
|
135 Message.__init__(self, filename, loc) |
|
136 self.message_args = (name, orig_loc.lineno) |
|
137 |
|
138 |
|
139 class ImportStarUsed(Message): |
|
140 """ |
|
141 Class defining the "Import Star Used" message. |
|
142 """ |
|
143 message = QT_TRANSLATE_NOOP( |
|
144 'py3Flakes', |
|
145 "'from {0} import *' used; unable to detect undefined names.") |
|
146 |
|
147 def __init__(self, filename, loc, modname): |
|
148 """ |
|
149 Constructor |
|
150 |
|
151 @param filename name of the file (string) |
|
152 @param loc location of warning (object) |
|
153 @param modname name of the module imported using star import (string) |
|
154 """ |
|
155 Message.__init__(self, filename, loc) |
|
156 self.message_args = (modname,) |
|
157 |
|
158 |
|
159 class UndefinedName(Message): |
|
160 """ |
|
161 Class defining the "Undefined Name" message. |
|
162 """ |
|
163 message = QT_TRANSLATE_NOOP('py3Flakes', 'Undefined name {0!r}.') |
|
164 |
|
165 def __init__(self, filename, loc, name): |
|
166 """ |
|
167 Constructor |
|
168 |
|
169 @param filename name of the file (string) |
|
170 @param loc location of warning (object) |
|
171 @param name undefined name (string) |
|
172 """ |
|
173 Message.__init__(self, filename, loc) |
|
174 self.message_args = (name,) |
|
175 |
|
176 |
|
177 class DoctestSyntaxError(Message): |
|
178 """ |
|
179 Class defining the "Syntax error in doctest" message. |
|
180 """ |
|
181 message = QT_TRANSLATE_NOOP('py3Flakes', 'Syntax error in doctest.') |
|
182 |
|
183 def __init__(self, filename, loc, position=None): |
|
184 """ |
|
185 Constructor |
|
186 |
|
187 @param filename name of the file (string) |
|
188 @param loc location of warning (object) |
|
189 @keyparam position of warning if existent (object) |
|
190 """ |
|
191 Message.__init__(self, filename, loc) |
|
192 if position: |
|
193 (self.lineno, self.col) = position |
|
194 self.message_args = () |
|
195 |
|
196 |
|
197 class UndefinedExport(Message): |
|
198 """ |
|
199 Class defining the "Undefined Export" message. |
|
200 """ |
|
201 message = QT_TRANSLATE_NOOP( |
|
202 'py3Flakes', |
|
203 'Undefined name {0!r} in __all__.') |
|
204 |
|
205 def __init__(self, filename, loc, name): |
|
206 """ |
|
207 Constructor |
|
208 |
|
209 @param filename name of the file (string) |
|
210 @param loc location of warning (object) |
|
211 @param name undefined exported name (string) |
|
212 """ |
|
213 Message.__init__(self, filename, loc) |
|
214 self.message_args = (name,) |
|
215 |
|
216 |
|
217 class UndefinedLocal(Message): |
|
218 """ |
|
219 Class defining the "Undefined Local Variable" message. |
|
220 """ |
|
221 message = QT_TRANSLATE_NOOP( |
|
222 'py3Flakes', |
|
223 "Local variable {0!r} (defined in enclosing scope on line {1!r})" |
|
224 " referenced before assignment.") |
|
225 |
|
226 def __init__(self, filename, loc, name, orig_loc): |
|
227 """ |
|
228 Constructor |
|
229 |
|
230 @param filename name of the file (string) |
|
231 @param loc location of warning (object) |
|
232 @param name name of the prematurely referenced variable (string) |
|
233 @param orig_loc location of the variable definition (object) |
|
234 """ |
|
235 Message.__init__(self, filename, loc) |
|
236 self.message_args = (name, orig_loc.lineno) |
|
237 |
|
238 |
|
239 class DuplicateArgument(Message): |
|
240 """ |
|
241 Class defining the "Duplicate Argument" message. |
|
242 """ |
|
243 message = QT_TRANSLATE_NOOP( |
|
244 'py3Flakes', |
|
245 'Duplicate argument {0!r} in function definition.') |
|
246 |
|
247 def __init__(self, filename, loc, name): |
|
248 """ |
|
249 Constructor |
|
250 |
|
251 @param filename name of the file (string) |
|
252 @param loc location of warning (object) |
|
253 @param name name of the duplicate argument (string) |
|
254 """ |
|
255 Message.__init__(self, filename, loc) |
|
256 self.message_args = (name,) |
|
257 |
|
258 |
|
259 class Redefined(Message): |
|
260 """ |
|
261 Class defining the "Redefined" message. |
|
262 """ |
|
263 message = QT_TRANSLATE_NOOP( |
|
264 'py3Flakes', |
|
265 'Redefinition of {0!r} from line {1!r}.') |
|
266 |
|
267 def __init__(self, filename, loc, name, orig_loc): |
|
268 """ |
|
269 Constructor |
|
270 |
|
271 @param filename name of the file (string) |
|
272 @param loc location of warning (object) |
|
273 @param name name of the redefined function (string) |
|
274 @param orig_loc location of the original definition (object) |
|
275 """ |
|
276 Message.__init__(self, filename, loc) |
|
277 self.message_args = (name, orig_loc.lineno) |
|
278 |
|
279 |
|
280 class LateFutureImport(Message): |
|
281 """ |
|
282 Class defining the "Late Future Import" message. |
|
283 """ |
|
284 message = QT_TRANSLATE_NOOP( |
|
285 'py3Flakes', |
|
286 'Future import(s) {0!r} after other statements.') |
|
287 |
|
288 def __init__(self, filename, loc, names): |
|
289 """ |
|
290 Constructor |
|
291 |
|
292 @param filename name of the file (string) |
|
293 @param loc location of warning (object) |
|
294 @param names names of the imported futures (string) |
|
295 """ |
|
296 Message.__init__(self, filename, loc) |
|
297 self.message_args = (names,) |
|
298 |
|
299 |
|
300 class UnusedVariable(Message): |
|
301 """ |
|
302 Class defining the "Unused Variable" message. |
|
303 |
|
304 Indicates that a variable has been explicitly assigned to but not actually |
|
305 used. |
|
306 """ |
|
307 message = QT_TRANSLATE_NOOP( |
|
308 'py3Flakes', |
|
309 'Local variable {0!r} is assigned to but never used.') |
|
310 |
|
311 def __init__(self, filename, loc, names): |
|
312 """ |
|
313 Constructor |
|
314 |
|
315 @param filename name of the file (string) |
|
316 @param loc location of warning (object) |
|
317 @param names names of the unused variable (string) |
|
318 """ |
|
319 Message.__init__(self, filename, loc) |
|
320 self.message_args = (names,) |