UtilitiesPython2/pyflakes/messages.py

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

eric ide

mercurial