eric6/Plugins/CheckerPlugins/SyntaxChecker/pyflakes/messages.py

changeset 6942
2602857055c5
parent 6766
c722fcfb5f62
child 7064
1010f737def2
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2010 - 2019 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 for Python2 and Python3, but was modified to
8 # be integrated into eric6
9
10 """
11 Module providing the class Message and its subclasses.
12 """
13
14
15 class Message(object):
16 """
17 Class defining the base for all specific message classes.
18 """
19 message_id = 'F00'
20 message = ''
21 message_args = ()
22
23 def __init__(self, filename, loc):
24 """
25 Constructor
26
27 @param filename name of the file (string)
28 @param loc location of the issue
29 """
30 self.filename = filename
31 self.lineno = loc.lineno
32 self.col = getattr(loc, 'col_offset', 0)
33
34 def __str__(self):
35 """
36 Special method return a string representation of the instance object.
37
38 @return string representation of the object (string)
39 """
40 return '{0}:{1}: {2}'.format(
41 self.filename, self.lineno, self.message % self.message_args)
42
43 def getMessageData(self):
44 """
45 Public method to get the individual message data elements.
46
47 @return tuple containing file name, line number, column, message ID
48 and message arguments (string, integer, integer, string, list)
49 """
50 return (self.filename, self.lineno, self.col, self.message_id,
51 self.message_args)
52
53
54 class UnusedImport(Message):
55 """
56 Class defining the "Unused Import" message.
57 """
58 message_id = 'F01'
59 message = '%r imported but unused'
60
61 def __init__(self, filename, loc, name):
62 """
63 Constructor
64
65 @param filename name of the file (string)
66 @param loc location of the issue
67 @param name name of the unused import (string)
68 """
69 Message.__init__(self, filename, loc)
70 self.message_args = (name,)
71
72
73 class RedefinedWhileUnused(Message):
74 """
75 Class defining the "Redefined While Unused" message.
76 """
77 message_id = 'F02'
78 message = 'redefinition of unused %r from line %r'
79
80 def __init__(self, filename, loc, name, orig_loc):
81 """
82 Constructor
83
84 @param filename name of the file (string)
85 @param loc location of the issue
86 @param name name of the redefined object (string)
87 @param orig_loc location of the original definition
88 """
89 Message.__init__(self, filename, loc)
90 self.message_args = (name, orig_loc.lineno)
91
92
93 class RedefinedInListComp(Message):
94 """
95 Class defining the "Redefined In List Comprehension" message.
96 """
97 message_id = 'F12'
98 message = 'list comprehension redefines %r from line %r'
99
100 def __init__(self, filename, loc, name, orig_loc):
101 """
102 Constructor
103
104 @param filename name of the file (string)
105 @param loc location of the issue
106 @param name name of the redefined object (string)
107 @param orig_loc location of the original definition
108 """
109 Message.__init__(self, filename, loc)
110 self.message_args = (name, orig_loc.lineno)
111
112
113 class ImportShadowedByLoopVar(Message):
114 """
115 Class defining the "Import Shadowed By Loop Var" message.
116 """
117 message_id = 'F03'
118 message = 'import %r from line %r shadowed by loop variable'
119
120 def __init__(self, filename, loc, name, orig_loc):
121 """
122 Constructor
123
124 @param filename name of the file (string)
125 @param loc location of the issue
126 @param name name of the shadowed import (string)
127 @param orig_loc location of the import
128 """
129 Message.__init__(self, filename, loc)
130 self.message_args = (name, orig_loc.lineno)
131
132
133 class ImportStarNotPermitted(Message):
134 """
135 Class defining the "Import * not permitted" message.
136 """
137 message_id = 'F16'
138 message = "'from %s import *' only allowed at module level"
139
140 def __init__(self, filename, loc, modname):
141 """
142 Constructor
143
144 @param filename name of the file (string)
145 @param loc location of the issue
146 @param modname name of the module (string)
147 """
148 Message.__init__(self, filename, loc)
149 self.message_args = (modname,)
150
151
152 class ImportStarUsed(Message):
153 """
154 Class defining the "Import Star Used" message.
155 """
156 message_id = 'F04'
157 message = "'from %s import *' used; unable to detect undefined names"
158
159 def __init__(self, filename, loc, modname):
160 """
161 Constructor
162
163 @param filename name of the file (string)
164 @param loc location of the issue
165 @param modname name of the module imported using star import (string)
166 """
167 Message.__init__(self, filename, loc)
168 self.message_args = (modname,)
169
170
171 class ImportStarUsage(Message):
172 """
173 Class defining the "Import Star Usage" message.
174 """
175 message_id = 'F17'
176 message = "%r may be undefined, or defined from star imports: %s"
177
178 def __init__(self, filename, loc, name, from_list):
179 """
180 Constructor
181
182 @param filename name of the file (string)
183 @param loc location of the issue
184 @param name name of the variable (string)
185 @param from_list list of modules imported from with * (string)
186 """
187 Message.__init__(self, filename, loc)
188 self.message_args = (name, from_list)
189
190
191 class UndefinedName(Message):
192 """
193 Class defining the "Undefined Name" message.
194 """
195 message_id = 'F05'
196 message = 'undefined name %r'
197
198 def __init__(self, filename, loc, name):
199 """
200 Constructor
201
202 @param filename name of the file (string)
203 @param loc location of the issue
204 @param name undefined name (string)
205 """
206 Message.__init__(self, filename, loc)
207 self.message_args = (name,)
208
209
210 class DoctestSyntaxError(Message):
211 """
212 Class defining the "Doctest syntax Error" message.
213 """
214 message_id = 'F13'
215 message = 'syntax error in doctest'
216
217 def __init__(self, filename, loc, position=None):
218 """
219 Constructor
220
221 @param filename name of the file (string)
222 @param loc location of the issue
223 @param position position of the syntax error
224 """
225 Message.__init__(self, filename, loc)
226 if position:
227 (self.lineno, self.col) = position
228 self.message_args = ()
229
230
231 class UndefinedExport(Message):
232 """
233 Class defining the "Undefined Export" message.
234 """
235 message_id = 'F06'
236 message = 'undefined name %r in __all__'
237
238 def __init__(self, filename, loc, name):
239 """
240 Constructor
241
242 @param filename name of the file (string)
243 @param loc location of the issue
244 @param name undefined exported name (string)
245 """
246 Message.__init__(self, filename, loc)
247 self.message_args = (name,)
248
249
250 class UndefinedLocal(Message):
251 """
252 Class defining the "Undefined Local Variable" message.
253 """
254 message_id = 'F07'
255 message = 'local variable %r {0} referenced before assignment'
256
257 default = 'defined in enclosing scope on line %r'
258 builtin = 'defined as a builtin'
259
260 def __init__(self, filename, loc, name, orig_loc):
261 """
262 Constructor
263
264 @param filename name of the file (string)
265 @param loc location of the issue
266 @param name name of the prematurely referenced variable (string)
267 @param orig_loc location of the variable definition
268 """
269 Message.__init__(self, filename, loc)
270 if orig_loc is None:
271 self.message = self.message.format(self.builtin)
272 self.message_args = (name,)
273 self.message_id = 'F07B'
274 else:
275 self.message = self.message.format(self.default)
276 self.message_args = (name, orig_loc.lineno)
277 self.message_id = 'F07A'
278
279
280 class DuplicateArgument(Message):
281 """
282 Class defining the "Duplicate Argument" message.
283 """
284 message_id = 'F08'
285 message = 'duplicate argument %r in function definition'
286
287 def __init__(self, filename, loc, name):
288 """
289 Constructor
290
291 @param filename name of the file (string)
292 @param loc location of the issue
293 @param name name of the duplicate argument (string)
294 """
295 Message.__init__(self, filename, loc)
296 self.message_args = (name,)
297
298
299 class MultiValueRepeatedKeyLiteral(Message):
300 """
301 Class defining the multiple used dictionary key message.
302 """
303 message_id = 'F18'
304 message = 'dictionary key %r repeated with different values'
305
306 def __init__(self, filename, loc, key):
307 """
308 Constructor
309
310 @param filename name of the file (string)
311 @param loc location of the issue
312 @param key dictionary key (string)
313 """
314 Message.__init__(self, filename, loc)
315 self.message_args = (key,)
316
317
318 class MultiValueRepeatedKeyVariable(Message):
319 """
320 Class defining the multiple used dictionary key variable message.
321 """
322 message_id = 'F19'
323 message = 'dictionary key variable %s repeated with different values'
324
325 def __init__(self, filename, loc, key):
326 """
327 Constructor
328
329 @param filename name of the file (string)
330 @param loc location of the issue
331 @param key dictionary key variable (string)
332 """
333 Message.__init__(self, filename, loc)
334 self.message_args = (key,)
335
336
337 class LateFutureImport(Message):
338 """
339 Class defining the "Late Future Import" message.
340 """
341 message_id = 'F10'
342 message = 'from __future__ imports must occur at the beginning of the file'
343
344 def __init__(self, filename, loc, names):
345 """
346 Constructor
347
348 @param filename name of the file (string)
349 @param loc location of the issue
350 @param names names of the imported futures (string)
351 """
352 Message.__init__(self, filename, loc)
353 self.message_args = ()
354
355
356 class FutureFeatureNotDefined(Message):
357 """
358 Class defining the undefined __future__ feature message.
359 """
360 message_id = 'F20'
361 message = 'future feature %s is not defined'
362
363 def __init__(self, filename, loc, name):
364 """
365 Constructor
366
367 @param filename name of the file (string)
368 @param loc location of the issue
369 @param name name of the imported undefined future feature (string)
370 """
371 Message.__init__(self, filename, loc)
372 self.message_args = (name,)
373
374
375 class UnusedVariable(Message):
376 """
377 Class defining the "Unused Variable" message.
378
379 Indicates that a variable has been explicitly assigned to but not actually
380 used.
381 """
382 message_id = 'F11'
383 message = 'local variable %r is assigned to but never used'
384
385 def __init__(self, filename, loc, names):
386 """
387 Constructor
388
389 @param filename name of the file (string)
390 @param loc location of the issue
391 @param names names of unused variable (string)
392 """
393 Message.__init__(self, filename, loc)
394 self.message_args = (names,)
395
396
397 class ReturnWithArgsInsideGenerator(Message):
398 """
399 Class defining the "Return values in generator" message.
400
401 Indicates a return statement with arguments inside a generator.
402 """
403 message_id = 'F14'
404 message = '\'return\' with argument inside generator'
405
406
407 class ReturnOutsideFunction(Message):
408 """
409 Class defining the "Return outside function" message.
410
411 Indicates a return statement outside of a function/method.
412 """
413 message_id = 'F15'
414 message = '\'return\' outside function'
415
416
417 class YieldOutsideFunction(Message):
418 """
419 Class defining the "Yield outside function" message.
420
421 Indicates a yield or yield from statement outside of a function/method.
422 """
423 message_id = 'F21'
424 message = '\'yield\' outside function'
425
426
427 # For whatever reason, Python gives different error messages for these two. We
428 # match the Python error message exactly.
429 class ContinueOutsideLoop(Message):
430 """
431 Class defining the "Continue outside loop" message.
432
433 Indicates a continue statement outside of a while or for loop.
434 """
435 message_id = 'F22'
436 message = '\'continue\' not properly in loop'
437
438
439 class BreakOutsideLoop(Message):
440 """
441 Class defining the "Break outside loop" message.
442
443 Indicates a break statement outside of a while or for loop.
444 """
445 message_id = 'F23'
446 message = '\'break\' outside loop'
447
448
449 class ContinueInFinally(Message):
450 """
451 Class defining the "Continue in finally block" message.
452
453 Indicates a continue statement in a finally block in a while or for loop.
454 """
455 message_id = 'F24'
456 message = '\'continue\' not supported inside \'finally\' clause'
457
458
459 class DefaultExceptNotLast(Message):
460 """
461 Class defining the "Default except not being the last" message.
462
463 Indicates an except block as not the last exception handler.
464 """
465 message_id = 'F25'
466 message = 'default \'except:\' must be last'
467
468
469 class TwoStarredExpressions(Message):
470 """
471 Class defining the "multiple starred expressions" message.
472
473 Two or more starred expressions in an assignment (a, *b, *c = d).
474 """
475 message_id = 'F26'
476 message = 'two starred expressions in assignment'
477
478
479 class TooManyExpressionsInStarredAssignment(Message):
480 """
481 Class defining the "too many starred expressions" message.
482
483 Too many expressions in an assignment with star-unpacking
484 """
485 message_id = 'F27'
486 message = 'too many expressions in star-unpacking assignment'
487
488
489 class AssertTuple(Message):
490 """
491 Class defining the "tuple assertion" message.
492
493 Assertion test is a tuple, which are always True.
494 """
495 message_id = 'F28'
496 message = 'assertion is always true, perhaps remove parentheses?'
497
498
499 class ForwardAnnotationSyntaxError(Message):
500 """
501 Class defining the "forward annotation syntax error" message.
502
503 Found a syntax error in forward annotation.
504 """
505 message_id = 'F29'
506 message = 'syntax error in forward annotation %r'
507
508 def __init__(self, filename, loc, annotation):
509 """
510 Constructor
511
512 @param filename name of the file (string)
513 @param loc location of the issue
514 @param annotation erroneous forward annotation (string)
515 """
516 Message.__init__(self, filename, loc)
517 self.message_args = (annotation,)
518
519
520 class CommentAnnotationSyntaxError(Message):
521 """
522 Class defining the "Comment Annotation Syntax Error" message.
523
524 Indicates a syntax error in a type comment.
525 """
526 message_id = 'F31'
527 message = 'syntax error in type comment %r'
528
529 def __init__(self, filename, loc, annotation):
530 """
531 Constructor
532
533 @param filename name of the file (string)
534 @param loc location of the issue
535 @param annotation erroneous forward annotation (string)
536 """
537 Message.__init__(self, filename, loc)
538 self.message_args = (annotation,)
539
540
541 class RaiseNotImplemented(Message):
542 """
543 Class defining the "raise not implemented" message.
544
545 Use NotImplementedError instead of NotImplemented.
546 """
547 message_id = 'F30'
548 message = "'raise NotImplemented' should be 'raise NotImplementedError'"
549
550
551 class InvalidPrintSyntax(Message):
552 """
553 Class defining the "Invalid Print Syntax" message.
554
555 Indicates the use of >> with a print function.
556 """
557 message_id = 'F32'
558 message = 'use of >> is invalid with print function'
559
560
561 class IsLiteral(Message):
562 """
563 Class defining the "Is Literal" message.
564
565 Indicates the use of "is" or "is not" against str, int and bytes.
566 """
567 message_id = 'F33'
568 message = 'use ==/!= to compare str, bytes, and int literals'
569
570 #
571 # eflag: noqa = M702

eric ide

mercurial