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