Merge lp:~florent.x/pyflakes/989203-python3 into lp:pyflakes
- 989203-python3
- Merge into master
Proposed by
Florent
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 53 | ||||
Proposed branch: | lp:~florent.x/pyflakes/989203-python3 | ||||
Merge into: | lp:pyflakes | ||||
Diff against target: |
814 lines (+215/-149) 9 files modified
.travis.yml (+5/-1) pyflakes/checker.py (+128/-96) pyflakes/reporter.py (+11/-7) pyflakes/scripts/pyflakes.py (+7/-5) pyflakes/test/harness.py (+2/-2) pyflakes/test/test_imports.py (+23/-17) pyflakes/test/test_script.py (+28/-15) pyflakes/test/test_undefined_names.py (+9/-6) setup.py (+2/-0) |
||||
To merge this branch: | bzr merge lp:~florent.x/pyflakes/989203-python3 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Pyflakes Dev | Pending | ||
Review via email:
|
Commit message
Description of the change
This branch brings the minimal changes to achieve Python 3 support.
Tests are green: https:/
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file '.travis.yml' | |||
2 | --- .travis.yml 2013-01-19 00:26:52 +0000 | |||
3 | +++ .travis.yml 2013-01-24 10:27:21 +0000 | |||
4 | @@ -3,10 +3,14 @@ | |||
5 | 3 | - 2.5 | 3 | - 2.5 |
6 | 4 | - 2.6 | 4 | - 2.6 |
7 | 5 | - 2.7 | 5 | - 2.7 |
8 | 6 | - 3.2 | ||
9 | 7 | - 3.3 | ||
10 | 6 | - pypy | 8 | - pypy |
11 | 9 | before_install: | ||
12 | 10 | - if [ "${TRAVIS_PYTHON_VERSION::1}" == "3" ]; then export TEST_PKG=unittest2py3k; else export TEST_PKG=unittest2; fi | ||
13 | 7 | install: | 11 | install: |
14 | 8 | - python setup.py install | 12 | - python setup.py install |
16 | 9 | - pip install unittest2 | 13 | - pip install $TEST_PKG |
17 | 10 | script: | 14 | script: |
18 | 11 | - unit2 discover | 15 | - unit2 discover |
19 | 12 | matrix: | 16 | matrix: |
20 | 13 | 17 | ||
21 | === modified file 'pyflakes/checker.py' | |||
22 | --- pyflakes/checker.py 2012-01-10 19:09:22 +0000 | |||
23 | +++ pyflakes/checker.py 2013-01-24 10:27:21 +0000 | |||
24 | @@ -2,9 +2,14 @@ | |||
25 | 2 | # (c) 2005-2010 Divmod, Inc. | 2 | # (c) 2005-2010 Divmod, Inc. |
26 | 3 | # See LICENSE file for details | 3 | # See LICENSE file for details |
27 | 4 | 4 | ||
28 | 5 | import __builtin__ | ||
29 | 6 | import os.path | 5 | import os.path |
30 | 7 | import _ast | 6 | import _ast |
31 | 7 | try: | ||
32 | 8 | import builtins | ||
33 | 9 | PY2 = False | ||
34 | 10 | except ImportError: | ||
35 | 11 | import __builtin__ as builtins | ||
36 | 12 | PY2 = True | ||
37 | 8 | 13 | ||
38 | 9 | from pyflakes import messages | 14 | from pyflakes import messages |
39 | 10 | 15 | ||
40 | @@ -173,11 +178,18 @@ | |||
41 | 173 | pass | 178 | pass |
42 | 174 | 179 | ||
43 | 175 | 180 | ||
45 | 176 | # Globally defined names which are not attributes of the __builtin__ module, or | 181 | # Globally defined names which are not attributes of the builtins module, or |
46 | 177 | # are only present on some platforms. | 182 | # are only present on some platforms. |
47 | 178 | _MAGIC_GLOBALS = ['__file__', '__builtins__', 'WindowsError'] | 183 | _MAGIC_GLOBALS = ['__file__', '__builtins__', 'WindowsError'] |
48 | 179 | 184 | ||
49 | 180 | 185 | ||
50 | 186 | def getNodeName(node): | ||
51 | 187 | # Returns node.id, or node.name, or None | ||
52 | 188 | if hasattr(node, 'id'): # One of the many nodes with an id | ||
53 | 189 | return node.id | ||
54 | 190 | if hasattr(node, 'name'): # a ExceptHandler node | ||
55 | 191 | return node.name | ||
56 | 192 | |||
57 | 181 | 193 | ||
58 | 182 | class Checker(object): | 194 | class Checker(object): |
59 | 183 | """ | 195 | """ |
60 | @@ -275,7 +287,7 @@ | |||
61 | 275 | all = [] | 287 | all = [] |
62 | 276 | 288 | ||
63 | 277 | # Look for imported names that aren't used. | 289 | # Look for imported names that aren't used. |
65 | 278 | for importation in scope.itervalues(): | 290 | for importation in scope.values(): |
66 | 279 | if isinstance(importation, Importation): | 291 | if isinstance(importation, Importation): |
67 | 280 | if not importation.used and importation.name not in all: | 292 | if not importation.used and importation.name not in all: |
68 | 281 | self.report( | 293 | self.report( |
69 | @@ -293,6 +305,83 @@ | |||
70 | 293 | def report(self, messageClass, *args, **kwargs): | 305 | def report(self, messageClass, *args, **kwargs): |
71 | 294 | self.messages.append(messageClass(self.filename, *args, **kwargs)) | 306 | self.messages.append(messageClass(self.filename, *args, **kwargs)) |
72 | 295 | 307 | ||
73 | 308 | def handleNodeLoad(self, node): | ||
74 | 309 | name = getNodeName(node) | ||
75 | 310 | if not name: | ||
76 | 311 | return | ||
77 | 312 | # try local scope | ||
78 | 313 | importStarred = self.scope.importStarred | ||
79 | 314 | try: | ||
80 | 315 | self.scope[name].used = (self.scope, node.lineno) | ||
81 | 316 | except KeyError: | ||
82 | 317 | pass | ||
83 | 318 | else: | ||
84 | 319 | return | ||
85 | 320 | |||
86 | 321 | # try enclosing function scopes | ||
87 | 322 | for scope in self.scopeStack[-2:0:-1]: | ||
88 | 323 | importStarred = importStarred or scope.importStarred | ||
89 | 324 | if not isinstance(scope, FunctionScope): | ||
90 | 325 | continue | ||
91 | 326 | try: | ||
92 | 327 | scope[name].used = (self.scope, node.lineno) | ||
93 | 328 | except KeyError: | ||
94 | 329 | pass | ||
95 | 330 | else: | ||
96 | 331 | return | ||
97 | 332 | |||
98 | 333 | # try global scope | ||
99 | 334 | importStarred = importStarred or self.scopeStack[0].importStarred | ||
100 | 335 | try: | ||
101 | 336 | self.scopeStack[0][name].used = (self.scope, node.lineno) | ||
102 | 337 | except KeyError: | ||
103 | 338 | if ((not hasattr(builtins, name)) and name not in _MAGIC_GLOBALS and not importStarred): | ||
104 | 339 | if (os.path.basename(self.filename) == '__init__.py' and name == '__path__'): | ||
105 | 340 | # the special name __path__ is valid only in packages | ||
106 | 341 | pass | ||
107 | 342 | else: | ||
108 | 343 | self.report(messages.UndefinedName, node.lineno, name) | ||
109 | 344 | |||
110 | 345 | def handleNodeStore(self, node): | ||
111 | 346 | name = getNodeName(node) | ||
112 | 347 | if not name: | ||
113 | 348 | return | ||
114 | 349 | # if the name hasn't already been defined in the current scope | ||
115 | 350 | if isinstance(self.scope, FunctionScope) and name not in self.scope: | ||
116 | 351 | # for each function or module scope above us | ||
117 | 352 | for scope in self.scopeStack[:-1]: | ||
118 | 353 | if not isinstance(scope, (FunctionScope, ModuleScope)): | ||
119 | 354 | continue | ||
120 | 355 | # if the name was defined in that scope, and the name has | ||
121 | 356 | # been accessed already in the current scope, and hasn't | ||
122 | 357 | # been declared global | ||
123 | 358 | if (name in scope and scope[name].used and scope[name].used[0] is self.scope | ||
124 | 359 | and name not in self.scope.globals): | ||
125 | 360 | # then it's probably a mistake | ||
126 | 361 | self.report(messages.UndefinedLocal, scope[name].used[1], name, | ||
127 | 362 | scope[name].source.lineno) | ||
128 | 363 | break | ||
129 | 364 | |||
130 | 365 | parent = getattr(node, 'parent', None) | ||
131 | 366 | if isinstance(parent, (_ast.For, _ast.comprehension, _ast.Tuple, _ast.List)): | ||
132 | 367 | binding = Binding(name, node) | ||
133 | 368 | elif parent is not None and name == '__all__' and isinstance(self.scope, ModuleScope): | ||
134 | 369 | binding = ExportBinding(name, parent.value) | ||
135 | 370 | else: | ||
136 | 371 | binding = Assignment(name, node) | ||
137 | 372 | if name in self.scope: | ||
138 | 373 | binding.used = self.scope[name].used | ||
139 | 374 | self.addBinding(node.lineno, binding) | ||
140 | 375 | |||
141 | 376 | def handleNodeDelete(self, node): | ||
142 | 377 | name = getNodeName(node) | ||
143 | 378 | if not name: | ||
144 | 379 | return | ||
145 | 380 | if isinstance(self.scope, FunctionScope) and name in self.scope.globals: | ||
146 | 381 | del self.scope.globals[name] | ||
147 | 382 | else: | ||
148 | 383 | self.addBinding(node.lineno, UnBinding(name, node)) | ||
149 | 384 | |||
150 | 296 | def handleChildren(self, tree): | 385 | def handleChildren(self, tree): |
151 | 297 | for node in iter_child_nodes(tree): | 386 | for node in iter_child_nodes(tree): |
152 | 298 | self.handleNode(node, tree) | 387 | self.handleNode(node, tree) |
153 | @@ -309,7 +398,7 @@ | |||
154 | 309 | def handleNode(self, node, parent): | 398 | def handleNode(self, node, parent): |
155 | 310 | node.parent = parent | 399 | node.parent = parent |
156 | 311 | if self.traceTree: | 400 | if self.traceTree: |
158 | 312 | print ' ' * self.nodeDepth + node.__class__.__name__ | 401 | print(' ' * self.nodeDepth + node.__class__.__name__) |
159 | 313 | self.nodeDepth += 1 | 402 | self.nodeDepth += 1 |
160 | 314 | if self.futuresAllowed and not \ | 403 | if self.futuresAllowed and not \ |
161 | 315 | (isinstance(node, _ast.ImportFrom) or self.isDocstring(node)): | 404 | (isinstance(node, _ast.ImportFrom) or self.isDocstring(node)): |
162 | @@ -321,14 +410,14 @@ | |||
163 | 321 | finally: | 410 | finally: |
164 | 322 | self.nodeDepth -= 1 | 411 | self.nodeDepth -= 1 |
165 | 323 | if self.traceTree: | 412 | if self.traceTree: |
167 | 324 | print ' ' * self.nodeDepth + 'end ' + node.__class__.__name__ | 413 | print(' ' * self.nodeDepth + 'end ' + node.__class__.__name__) |
168 | 325 | 414 | ||
169 | 326 | def ignore(self, node): | 415 | def ignore(self, node): |
170 | 327 | pass | 416 | pass |
171 | 328 | 417 | ||
172 | 329 | # "stmt" type nodes | 418 | # "stmt" type nodes |
175 | 330 | RETURN = DELETE = PRINT = WHILE = IF = WITH = RAISE = TRYEXCEPT = \ | 419 | RETURN = DELETE = PRINT = WHILE = IF = WITH = WITHITEM = RAISE = \ |
176 | 331 | TRYFINALLY = ASSERT = EXEC = EXPR = handleChildren | 420 | TRYEXCEPT = TRYFINALLY = TRY = ASSERT = EXEC = EXPR = handleChildren |
177 | 332 | 421 | ||
178 | 333 | CONTINUE = BREAK = PASS = ignore | 422 | CONTINUE = BREAK = PASS = ignore |
179 | 334 | 423 | ||
180 | @@ -350,7 +439,7 @@ | |||
181 | 350 | EQ = NOTEQ = LT = LTE = GT = GTE = IS = ISNOT = IN = NOTIN = ignore | 439 | EQ = NOTEQ = LT = LTE = GT = GTE = IS = ISNOT = IN = NOTIN = ignore |
182 | 351 | 440 | ||
183 | 352 | # additional node types | 441 | # additional node types |
185 | 353 | COMPREHENSION = EXCEPTHANDLER = KEYWORD = handleChildren | 442 | COMPREHENSION = KEYWORD = handleChildren |
186 | 354 | 443 | ||
187 | 355 | def addBinding(self, lineno, value, reportRedef=True): | 444 | def addBinding(self, lineno, value, reportRedef=True): |
188 | 356 | '''Called when a binding is altered. | 445 | '''Called when a binding is altered. |
189 | @@ -436,81 +525,11 @@ | |||
190 | 436 | """ | 525 | """ |
191 | 437 | # Locate the name in locals / function / globals scopes. | 526 | # Locate the name in locals / function / globals scopes. |
192 | 438 | if isinstance(node.ctx, (_ast.Load, _ast.AugLoad)): | 527 | if isinstance(node.ctx, (_ast.Load, _ast.AugLoad)): |
230 | 439 | # try local scope | 528 | self.handleNodeLoad(node) |
194 | 440 | importStarred = self.scope.importStarred | ||
195 | 441 | try: | ||
196 | 442 | self.scope[node.id].used = (self.scope, node.lineno) | ||
197 | 443 | except KeyError: | ||
198 | 444 | pass | ||
199 | 445 | else: | ||
200 | 446 | return | ||
201 | 447 | |||
202 | 448 | # try enclosing function scopes | ||
203 | 449 | |||
204 | 450 | for scope in self.scopeStack[-2:0:-1]: | ||
205 | 451 | importStarred = importStarred or scope.importStarred | ||
206 | 452 | if not isinstance(scope, FunctionScope): | ||
207 | 453 | continue | ||
208 | 454 | try: | ||
209 | 455 | scope[node.id].used = (self.scope, node.lineno) | ||
210 | 456 | except KeyError: | ||
211 | 457 | pass | ||
212 | 458 | else: | ||
213 | 459 | return | ||
214 | 460 | |||
215 | 461 | # try global scope | ||
216 | 462 | |||
217 | 463 | importStarred = importStarred or self.scopeStack[0].importStarred | ||
218 | 464 | try: | ||
219 | 465 | self.scopeStack[0][node.id].used = (self.scope, node.lineno) | ||
220 | 466 | except KeyError: | ||
221 | 467 | if ((not hasattr(__builtin__, node.id)) | ||
222 | 468 | and node.id not in _MAGIC_GLOBALS | ||
223 | 469 | and not importStarred): | ||
224 | 470 | if (os.path.basename(self.filename) == '__init__.py' and | ||
225 | 471 | node.id == '__path__'): | ||
226 | 472 | # the special name __path__ is valid only in packages | ||
227 | 473 | pass | ||
228 | 474 | else: | ||
229 | 475 | self.report(messages.UndefinedName, node.lineno, node.id) | ||
231 | 476 | elif isinstance(node.ctx, (_ast.Store, _ast.AugStore)): | 529 | elif isinstance(node.ctx, (_ast.Store, _ast.AugStore)): |
263 | 477 | # if the name hasn't already been defined in the current scope | 530 | self.handleNodeStore(node) |
233 | 478 | if isinstance(self.scope, FunctionScope) and node.id not in self.scope: | ||
234 | 479 | # for each function or module scope above us | ||
235 | 480 | for scope in self.scopeStack[:-1]: | ||
236 | 481 | if not isinstance(scope, (FunctionScope, ModuleScope)): | ||
237 | 482 | continue | ||
238 | 483 | # if the name was defined in that scope, and the name has | ||
239 | 484 | # been accessed already in the current scope, and hasn't | ||
240 | 485 | # been declared global | ||
241 | 486 | if (node.id in scope | ||
242 | 487 | and scope[node.id].used | ||
243 | 488 | and scope[node.id].used[0] is self.scope | ||
244 | 489 | and node.id not in self.scope.globals): | ||
245 | 490 | # then it's probably a mistake | ||
246 | 491 | self.report(messages.UndefinedLocal, | ||
247 | 492 | scope[node.id].used[1], | ||
248 | 493 | node.id, | ||
249 | 494 | scope[node.id].source.lineno) | ||
250 | 495 | break | ||
251 | 496 | |||
252 | 497 | if isinstance(node.parent, | ||
253 | 498 | (_ast.For, _ast.comprehension, _ast.Tuple, _ast.List)): | ||
254 | 499 | binding = Binding(node.id, node) | ||
255 | 500 | elif (node.id == '__all__' and | ||
256 | 501 | isinstance(self.scope, ModuleScope)): | ||
257 | 502 | binding = ExportBinding(node.id, node.parent.value) | ||
258 | 503 | else: | ||
259 | 504 | binding = Assignment(node.id, node) | ||
260 | 505 | if node.id in self.scope: | ||
261 | 506 | binding.used = self.scope[node.id].used | ||
262 | 507 | self.addBinding(node.lineno, binding) | ||
264 | 508 | elif isinstance(node.ctx, _ast.Del): | 531 | elif isinstance(node.ctx, _ast.Del): |
270 | 509 | if isinstance(self.scope, FunctionScope) and \ | 532 | self.handleNodeDelete(node) |
266 | 510 | node.id in self.scope.globals: | ||
267 | 511 | del self.scope.globals[node.id] | ||
268 | 512 | else: | ||
269 | 513 | self.addBinding(node.lineno, UnBinding(node.id, node)) | ||
271 | 514 | else: | 533 | else: |
272 | 515 | # must be a Param context -- this only happens for names in function | 534 | # must be a Param context -- this only happens for names in function |
273 | 516 | # arguments, but these aren't dispatched through here | 535 | # arguments, but these aren't dispatched through here |
274 | @@ -536,18 +555,28 @@ | |||
275 | 536 | def runFunction(): | 555 | def runFunction(): |
276 | 537 | args = [] | 556 | args = [] |
277 | 538 | 557 | ||
284 | 539 | def addArgs(arglist): | 558 | if PY2: |
285 | 540 | for arg in arglist: | 559 | def addArgs(arglist): |
286 | 541 | if isinstance(arg, _ast.Tuple): | 560 | for arg in arglist: |
287 | 542 | addArgs(arg.elts) | 561 | if isinstance(arg, _ast.Tuple): |
288 | 543 | else: | 562 | addArgs(arg.elts) |
289 | 544 | if arg.id in args: | 563 | else: |
290 | 564 | if arg.id in args: | ||
291 | 565 | self.report(messages.DuplicateArgument, | ||
292 | 566 | node.lineno, arg.id) | ||
293 | 567 | args.append(arg.id) | ||
294 | 568 | else: | ||
295 | 569 | def addArgs(arglist): | ||
296 | 570 | for arg in arglist: | ||
297 | 571 | if arg.arg in args: | ||
298 | 545 | self.report(messages.DuplicateArgument, | 572 | self.report(messages.DuplicateArgument, |
301 | 546 | node.lineno, arg.id) | 573 | node.lineno, arg.arg) |
302 | 547 | args.append(arg.id) | 574 | args.append(arg.arg) |
303 | 548 | 575 | ||
304 | 549 | self.pushFunctionScope() | 576 | self.pushFunctionScope() |
305 | 550 | addArgs(node.args.args) | 577 | addArgs(node.args.args) |
306 | 578 | if not PY2: | ||
307 | 579 | addArgs(node.args.kwonlyargs) | ||
308 | 551 | # vararg/kwarg identifiers are not Name nodes | 580 | # vararg/kwarg identifiers are not Name nodes |
309 | 552 | if node.args.vararg: | 581 | if node.args.vararg: |
310 | 553 | args.append(node.args.vararg) | 582 | args.append(node.args.vararg) |
311 | @@ -566,7 +595,7 @@ | |||
312 | 566 | """ | 595 | """ |
313 | 567 | Check to see if any assignments have not been used. | 596 | Check to see if any assignments have not been used. |
314 | 568 | """ | 597 | """ |
316 | 569 | for name, binding in self.scope.iteritems(): | 598 | for name, binding in self.scope.items(): |
317 | 570 | if (not binding.used and not name in self.scope.globals | 599 | if (not binding.used and not name in self.scope.globals |
318 | 571 | and isinstance(binding, Assignment)): | 600 | and isinstance(binding, Assignment)): |
319 | 572 | self.report(messages.UnusedVariable, | 601 | self.report(messages.UnusedVariable, |
320 | @@ -600,13 +629,9 @@ | |||
321 | 600 | self.handleNode(target, node) | 629 | self.handleNode(target, node) |
322 | 601 | 630 | ||
323 | 602 | def AUGASSIGN(self, node): | 631 | def AUGASSIGN(self, node): |
328 | 603 | # AugAssign is awkward: must set the context explicitly and visit twice, | 632 | self.handleNodeLoad(node.target) |
325 | 604 | # once with AugLoad context, once with AugStore context | ||
326 | 605 | node.target.ctx = _ast.AugLoad() | ||
327 | 606 | self.handleNode(node.target, node) | ||
329 | 607 | self.handleNode(node.value, node) | 633 | self.handleNode(node.value, node) |
332 | 608 | node.target.ctx = _ast.AugStore() | 634 | self.handleNodeStore(node.target) |
331 | 609 | self.handleNode(node.target, node) | ||
333 | 610 | 635 | ||
334 | 611 | def IMPORT(self, node): | 636 | def IMPORT(self, node): |
335 | 612 | for alias in node.names: | 637 | for alias in node.names: |
336 | @@ -632,3 +657,10 @@ | |||
337 | 632 | if node.module == '__future__': | 657 | if node.module == '__future__': |
338 | 633 | importation.used = (self.scope, node.lineno) | 658 | importation.used = (self.scope, node.lineno) |
339 | 634 | self.addBinding(node.lineno, importation) | 659 | self.addBinding(node.lineno, importation) |
340 | 660 | |||
341 | 661 | def EXCEPTHANDLER(self, node): | ||
342 | 662 | # in addition to handling children, we must handle the name of the exception, which is not | ||
343 | 663 | # a Name node, but a simple string. | ||
344 | 664 | if node.name: | ||
345 | 665 | self.handleNodeStore(node) | ||
346 | 666 | self.handleChildren(node) | ||
347 | 635 | 667 | ||
348 | === modified file 'pyflakes/reporter.py' | |||
349 | --- pyflakes/reporter.py 2012-10-23 13:07:35 +0000 | |||
350 | +++ pyflakes/reporter.py 2013-01-24 10:27:21 +0000 | |||
351 | @@ -2,6 +2,10 @@ | |||
352 | 2 | # See LICENSE file for details | 2 | # See LICENSE file for details |
353 | 3 | 3 | ||
354 | 4 | import sys | 4 | import sys |
355 | 5 | try: | ||
356 | 6 | u = unicode | ||
357 | 7 | except NameError: | ||
358 | 8 | u = str | ||
359 | 5 | 9 | ||
360 | 6 | 10 | ||
361 | 7 | class Reporter(object): | 11 | class Reporter(object): |
362 | @@ -33,7 +37,7 @@ | |||
363 | 33 | @param msg: A message explaining the problem. | 37 | @param msg: A message explaining the problem. |
364 | 34 | @ptype msg: C{unicode} | 38 | @ptype msg: C{unicode} |
365 | 35 | """ | 39 | """ |
367 | 36 | self._stderr.write(u"%s: %s\n" % (filename, msg)) | 40 | self._stderr.write(u("%s: %s\n") % (filename, msg)) |
368 | 37 | 41 | ||
369 | 38 | 42 | ||
370 | 39 | def syntaxError(self, filename, msg, lineno, offset, text): | 43 | def syntaxError(self, filename, msg, lineno, offset, text): |
371 | @@ -54,11 +58,11 @@ | |||
372 | 54 | line = text.splitlines()[-1] | 58 | line = text.splitlines()[-1] |
373 | 55 | if offset is not None: | 59 | if offset is not None: |
374 | 56 | offset = offset - (len(text) - len(line)) | 60 | offset = offset - (len(text) - len(line)) |
378 | 57 | self._stderr.write(u'%s:%d: %s\n' % (filename, lineno, msg)) | 61 | self._stderr.write(u('%s:%d: %s\n') % (filename, lineno, msg)) |
379 | 58 | self._stderr.write(line) | 62 | self._stderr.write(u(line)) |
380 | 59 | self._stderr.write(u'\n') | 63 | self._stderr.write(u('\n')) |
381 | 60 | if offset is not None: | 64 | if offset is not None: |
383 | 61 | self._stderr.write(u" " * (offset + 1) + u"^\n") | 65 | self._stderr.write(u(" " * (offset + 1) + "^\n")) |
384 | 62 | 66 | ||
385 | 63 | 67 | ||
386 | 64 | def flake(self, message): | 68 | def flake(self, message): |
387 | @@ -67,8 +71,8 @@ | |||
388 | 67 | 71 | ||
389 | 68 | @param: A L{pyflakes.messages.Message}. | 72 | @param: A L{pyflakes.messages.Message}. |
390 | 69 | """ | 73 | """ |
393 | 70 | self._stdout.write(unicode(message)) | 74 | self._stdout.write(u(message)) |
394 | 71 | self._stdout.write(u'\n') | 75 | self._stdout.write(u('\n')) |
395 | 72 | 76 | ||
396 | 73 | 77 | ||
397 | 74 | 78 | ||
398 | 75 | 79 | ||
399 | === modified file 'pyflakes/scripts/pyflakes.py' | |||
400 | --- pyflakes/scripts/pyflakes.py 2012-10-23 11:48:54 +0000 | |||
401 | +++ pyflakes/scripts/pyflakes.py 2013-01-24 10:27:21 +0000 | |||
402 | @@ -34,7 +34,8 @@ | |||
403 | 34 | # First, compile into an AST and handle syntax errors. | 34 | # First, compile into an AST and handle syntax errors. |
404 | 35 | try: | 35 | try: |
405 | 36 | tree = compile(codeString, filename, "exec", _ast.PyCF_ONLY_AST) | 36 | tree = compile(codeString, filename, "exec", _ast.PyCF_ONLY_AST) |
407 | 37 | except SyntaxError, value: | 37 | except SyntaxError: |
408 | 38 | value = sys.exc_info()[1] | ||
409 | 38 | msg = value.args[0] | 39 | msg = value.args[0] |
410 | 39 | 40 | ||
411 | 40 | (lineno, offset, text) = value.lineno, value.offset, value.text | 41 | (lineno, offset, text) = value.lineno, value.offset, value.text |
412 | @@ -44,14 +45,14 @@ | |||
413 | 44 | # Avoid using msg, since for the only known case, it contains a | 45 | # Avoid using msg, since for the only known case, it contains a |
414 | 45 | # bogus message that claims the encoding the file declared was | 46 | # bogus message that claims the encoding the file declared was |
415 | 46 | # unknown. | 47 | # unknown. |
417 | 47 | reporter.unexpectedError(filename, u'problem decoding source') | 48 | reporter.unexpectedError(filename, 'problem decoding source') |
418 | 48 | else: | 49 | else: |
419 | 49 | reporter.syntaxError(filename, msg, lineno, offset, text) | 50 | reporter.syntaxError(filename, msg, lineno, offset, text) |
420 | 50 | return 1 | 51 | return 1 |
421 | 51 | else: | 52 | else: |
422 | 52 | # Okay, it's syntactically valid. Now check it. | 53 | # Okay, it's syntactically valid. Now check it. |
423 | 53 | w = checker.Checker(tree, filename) | 54 | w = checker.Checker(tree, filename) |
425 | 54 | w.messages.sort(lambda a, b: cmp(a.lineno, b.lineno)) | 55 | w.messages.sort(key=lambda m: m.lineno) |
426 | 55 | for warning in w.messages: | 56 | for warning in w.messages: |
427 | 56 | reporter.flake(warning) | 57 | reporter.flake(warning) |
428 | 57 | return len(w.messages) | 58 | return len(w.messages) |
429 | @@ -69,8 +70,9 @@ | |||
430 | 69 | if reporter is None: | 70 | if reporter is None: |
431 | 70 | reporter = modReporter._makeDefaultReporter() | 71 | reporter = modReporter._makeDefaultReporter() |
432 | 71 | try: | 72 | try: |
435 | 72 | return check(file(filename, 'U').read() + '\n', filename, reporter) | 73 | return check(open(filename, 'U').read() + '\n', filename, reporter) |
436 | 73 | except IOError, msg: | 74 | except IOError: |
437 | 75 | msg = sys.exc_info()[1] | ||
438 | 74 | reporter.unexpectedError(filename, msg.args[1]) | 76 | reporter.unexpectedError(filename, msg.args[1]) |
439 | 75 | return 1 | 77 | return 1 |
440 | 76 | 78 | ||
441 | 77 | 79 | ||
442 | === modified file 'pyflakes/test/harness.py' | |||
443 | --- pyflakes/test/harness.py 2013-01-08 16:34:11 +0000 | |||
444 | +++ pyflakes/test/harness.py 2013-01-24 10:27:21 +0000 | |||
445 | @@ -15,8 +15,8 @@ | |||
446 | 15 | w = checker.Checker(ast, **kw) | 15 | w = checker.Checker(ast, **kw) |
447 | 16 | outputs = [type(o) for o in w.messages] | 16 | outputs = [type(o) for o in w.messages] |
448 | 17 | expectedOutputs = list(expectedOutputs) | 17 | expectedOutputs = list(expectedOutputs) |
451 | 18 | outputs.sort() | 18 | outputs.sort(key=lambda t: t.__name__) |
452 | 19 | expectedOutputs.sort() | 19 | expectedOutputs.sort(key=lambda t: t.__name__) |
453 | 20 | self.assertEqual(outputs, expectedOutputs, '''\ | 20 | self.assertEqual(outputs, expectedOutputs, '''\ |
454 | 21 | for input: | 21 | for input: |
455 | 22 | %s | 22 | %s |
456 | 23 | 23 | ||
457 | === modified file 'pyflakes/test/test_imports.py' | |||
458 | --- pyflakes/test/test_imports.py 2013-01-08 16:34:11 +0000 | |||
459 | +++ pyflakes/test/test_imports.py 2013-01-24 10:27:21 +0000 | |||
460 | @@ -16,8 +16,8 @@ | |||
461 | 16 | self.flakes('from moo import fu as FU, bar as FU', m.RedefinedWhileUnused, m.UnusedImport) | 16 | self.flakes('from moo import fu as FU, bar as FU', m.RedefinedWhileUnused, m.UnusedImport) |
462 | 17 | 17 | ||
463 | 18 | def test_usedImport(self): | 18 | def test_usedImport(self): |
466 | 19 | self.flakes('import fu; print fu') | 19 | self.flakes('import fu; print(fu)') |
467 | 20 | self.flakes('from baz import fu; print fu') | 20 | self.flakes('from baz import fu; print(fu)') |
468 | 21 | 21 | ||
469 | 22 | def test_redefinedWhileUnused(self): | 22 | def test_redefinedWhileUnused(self): |
470 | 23 | self.flakes('import fu; fu = 3', m.RedefinedWhileUnused) | 23 | self.flakes('import fu; fu = 3', m.RedefinedWhileUnused) |
471 | @@ -74,28 +74,28 @@ | |||
472 | 74 | import fu | 74 | import fu |
473 | 75 | class bar: | 75 | class bar: |
474 | 76 | fu = 1 | 76 | fu = 1 |
476 | 77 | print fu | 77 | print(fu) |
477 | 78 | ''') | 78 | ''') |
478 | 79 | 79 | ||
479 | 80 | def test_usedInFunction(self): | 80 | def test_usedInFunction(self): |
480 | 81 | self.flakes(''' | 81 | self.flakes(''' |
481 | 82 | import fu | 82 | import fu |
482 | 83 | def fun(): | 83 | def fun(): |
484 | 84 | print fu | 84 | print(fu) |
485 | 85 | ''') | 85 | ''') |
486 | 86 | 86 | ||
487 | 87 | def test_shadowedByParameter(self): | 87 | def test_shadowedByParameter(self): |
488 | 88 | self.flakes(''' | 88 | self.flakes(''' |
489 | 89 | import fu | 89 | import fu |
490 | 90 | def fun(fu): | 90 | def fun(fu): |
492 | 91 | print fu | 91 | print(fu) |
493 | 92 | ''', m.UnusedImport) | 92 | ''', m.UnusedImport) |
494 | 93 | 93 | ||
495 | 94 | self.flakes(''' | 94 | self.flakes(''' |
496 | 95 | import fu | 95 | import fu |
497 | 96 | def fun(fu): | 96 | def fun(fu): |
500 | 97 | print fu | 97 | print(fu) |
501 | 98 | print fu | 98 | print(fu) |
502 | 99 | ''') | 99 | ''') |
503 | 100 | 100 | ||
504 | 101 | def test_newAssignment(self): | 101 | def test_newAssignment(self): |
505 | @@ -106,12 +106,12 @@ | |||
506 | 106 | self.flakes('import fu; "bar".fu.baz', m.UnusedImport) | 106 | self.flakes('import fu; "bar".fu.baz', m.UnusedImport) |
507 | 107 | 107 | ||
508 | 108 | def test_usedInSlice(self): | 108 | def test_usedInSlice(self): |
510 | 109 | self.flakes('import fu; print fu.bar[1:]') | 109 | self.flakes('import fu; print(fu.bar[1:])') |
511 | 110 | 110 | ||
512 | 111 | def test_usedInIfBody(self): | 111 | def test_usedInIfBody(self): |
513 | 112 | self.flakes(''' | 112 | self.flakes(''' |
514 | 113 | import fu | 113 | import fu |
516 | 114 | if True: print fu | 114 | if True: print(fu) |
517 | 115 | ''') | 115 | ''') |
518 | 116 | 116 | ||
519 | 117 | def test_usedInIfConditional(self): | 117 | def test_usedInIfConditional(self): |
520 | @@ -131,7 +131,7 @@ | |||
521 | 131 | self.flakes(''' | 131 | self.flakes(''' |
522 | 132 | import fu | 132 | import fu |
523 | 133 | if False: pass | 133 | if False: pass |
525 | 134 | else: print fu | 134 | else: print(fu) |
526 | 135 | ''') | 135 | ''') |
527 | 136 | 136 | ||
528 | 137 | def test_usedInCall(self): | 137 | def test_usedInCall(self): |
529 | @@ -156,14 +156,14 @@ | |||
530 | 156 | import fu | 156 | import fu |
531 | 157 | def bleh(): | 157 | def bleh(): |
532 | 158 | pass | 158 | pass |
534 | 159 | print fu | 159 | print(fu) |
535 | 160 | ''') | 160 | ''') |
536 | 161 | 161 | ||
537 | 162 | def test_usedInFor(self): | 162 | def test_usedInFor(self): |
538 | 163 | self.flakes(''' | 163 | self.flakes(''' |
539 | 164 | import fu | 164 | import fu |
540 | 165 | for bar in range(9): | 165 | for bar in range(9): |
542 | 166 | print fu | 166 | print(fu) |
543 | 167 | ''') | 167 | ''') |
544 | 168 | 168 | ||
545 | 169 | def test_usedInForElse(self): | 169 | def test_usedInForElse(self): |
546 | @@ -172,7 +172,7 @@ | |||
547 | 172 | for bar in range(10): | 172 | for bar in range(10): |
548 | 173 | pass | 173 | pass |
549 | 174 | else: | 174 | else: |
551 | 175 | print fu | 175 | print(fu) |
552 | 176 | ''') | 176 | ''') |
553 | 177 | 177 | ||
554 | 178 | def test_redefinedByFor(self): | 178 | def test_redefinedByFor(self): |
555 | @@ -262,11 +262,12 @@ | |||
556 | 262 | ''') | 262 | ''') |
557 | 263 | 263 | ||
558 | 264 | def test_redefinedByExcept(self): | 264 | def test_redefinedByExcept(self): |
559 | 265 | as_exc = ', ' if version_info < (2, 6) else ' as ' | ||
560 | 265 | self.flakes(''' | 266 | self.flakes(''' |
561 | 266 | import fu | 267 | import fu |
562 | 267 | try: pass | 268 | try: pass |
565 | 268 | except Exception, fu: pass | 269 | except Exception%sfu: pass |
566 | 269 | ''', m.RedefinedWhileUnused) | 270 | ''' % as_exc, m.RedefinedWhileUnused) |
567 | 270 | 271 | ||
568 | 271 | def test_usedInRaise(self): | 272 | def test_usedInRaise(self): |
569 | 272 | self.flakes(''' | 273 | self.flakes(''' |
570 | @@ -341,11 +342,16 @@ | |||
571 | 341 | def f(): global fu | 342 | def f(): global fu |
572 | 342 | ''', m.UnusedImport) | 343 | ''', m.UnusedImport) |
573 | 343 | 344 | ||
574 | 345 | @skipIf(version_info >= (3,), 'deprecated syntax') | ||
575 | 344 | def test_usedInBackquote(self): | 346 | def test_usedInBackquote(self): |
576 | 345 | self.flakes('import fu; `fu`') | 347 | self.flakes('import fu; `fu`') |
577 | 346 | 348 | ||
578 | 347 | def test_usedInExec(self): | 349 | def test_usedInExec(self): |
580 | 348 | self.flakes('import fu; exec "print 1" in fu.bar') | 350 | if version_info < (3,): |
581 | 351 | exec_stmt = 'exec "print 1" in fu.bar' | ||
582 | 352 | else: | ||
583 | 353 | exec_stmt = 'exec("print(1)", fu.bar)' | ||
584 | 354 | self.flakes('import fu; %s' % exec_stmt) | ||
585 | 349 | 355 | ||
586 | 350 | def test_usedInLambda(self): | 356 | def test_usedInLambda(self): |
587 | 351 | self.flakes('import fu; lambda: fu') | 357 | self.flakes('import fu; lambda: fu') |
588 | @@ -385,7 +391,7 @@ | |||
589 | 385 | import fu | 391 | import fu |
590 | 386 | class b: | 392 | class b: |
591 | 387 | def c(self): | 393 | def c(self): |
593 | 388 | print fu | 394 | print(fu) |
594 | 389 | ''') | 395 | ''') |
595 | 390 | 396 | ||
596 | 391 | def test_importStar(self): | 397 | def test_importStar(self): |
597 | 392 | 398 | ||
598 | === modified file 'pyflakes/test/test_script.py' | |||
599 | --- pyflakes/test/test_script.py 2013-01-08 16:34:11 +0000 | |||
600 | +++ pyflakes/test/test_script.py 2013-01-24 10:27:21 +0000 | |||
601 | @@ -7,9 +7,12 @@ | |||
602 | 7 | import shutil | 7 | import shutil |
603 | 8 | import subprocess | 8 | import subprocess |
604 | 9 | import tempfile | 9 | import tempfile |
606 | 10 | from StringIO import StringIO | 10 | try: |
607 | 11 | from io import StringIO | ||
608 | 12 | except ImportError: | ||
609 | 13 | from StringIO import StringIO | ||
610 | 11 | 14 | ||
612 | 12 | from unittest2 import TestCase | 15 | from unittest2 import skipIf, TestCase |
613 | 13 | 16 | ||
614 | 14 | from pyflakes.messages import UnusedImport | 17 | from pyflakes.messages import UnusedImport |
615 | 15 | from pyflakes.reporter import Reporter | 18 | from pyflakes.reporter import Reporter |
616 | @@ -207,8 +210,8 @@ | |||
617 | 207 | """ | 210 | """ |
618 | 208 | err = StringIO() | 211 | err = StringIO() |
619 | 209 | reporter = Reporter(None, err) | 212 | reporter = Reporter(None, err) |
622 | 210 | reporter.unexpectedError(u'source.py', u'error message') | 213 | reporter.unexpectedError('source.py', 'error message') |
623 | 211 | self.assertEquals(u'source.py: error message\n', err.getvalue()) | 214 | self.assertEquals('source.py: error message\n', err.getvalue()) |
624 | 212 | 215 | ||
625 | 213 | 216 | ||
626 | 214 | def test_flake(self): | 217 | def test_flake(self): |
627 | @@ -234,6 +237,8 @@ | |||
628 | 234 | Make a temporary file containing C{content} and return a path to it. | 237 | Make a temporary file containing C{content} and return a path to it. |
629 | 235 | """ | 238 | """ |
630 | 236 | _, fpath = tempfile.mkstemp() | 239 | _, fpath = tempfile.mkstemp() |
631 | 240 | if not hasattr(content, 'decode'): | ||
632 | 241 | content = content.encode('ascii') | ||
633 | 237 | fd = open(fpath, 'wb') | 242 | fd = open(fpath, 'wb') |
634 | 238 | fd.write(content) | 243 | fd.write(content) |
635 | 239 | fd.close() | 244 | fd.close() |
636 | @@ -309,10 +314,11 @@ | |||
637 | 309 | # Sanity check - SyntaxError.text should be multiple lines, if it | 314 | # Sanity check - SyntaxError.text should be multiple lines, if it |
638 | 310 | # isn't, something this test was unprepared for has happened. | 315 | # isn't, something this test was unprepared for has happened. |
639 | 311 | def evaluate(source): | 316 | def evaluate(source): |
641 | 312 | exec source | 317 | exec(source) |
642 | 313 | try: | 318 | try: |
643 | 314 | evaluate(source) | 319 | evaluate(source) |
645 | 315 | except SyntaxError, e: | 320 | except SyntaxError: |
646 | 321 | e = sys.exc_info()[1] | ||
647 | 316 | self.assertTrue(e.text.count('\n') > 1) | 322 | self.assertTrue(e.text.count('\n') > 1) |
648 | 317 | else: | 323 | else: |
649 | 318 | self.fail() | 324 | self.fail() |
650 | @@ -353,12 +359,13 @@ | |||
651 | 353 | pass | 359 | pass |
652 | 354 | """ | 360 | """ |
653 | 355 | sourcePath = self.makeTempFile(source) | 361 | sourcePath = self.makeTempFile(source) |
654 | 362 | last_line = ' ^\n' if sys.version_info >= (3, 2) else '' | ||
655 | 356 | self.assertHasErrors( | 363 | self.assertHasErrors( |
656 | 357 | sourcePath, | 364 | sourcePath, |
657 | 358 | ["""\ | 365 | ["""\ |
658 | 359 | %s:1: non-default argument follows default argument | 366 | %s:1: non-default argument follows default argument |
659 | 360 | def foo(bar=baz, bax): | 367 | def foo(bar=baz, bax): |
661 | 361 | """ % (sourcePath,)]) | 368 | %s""" % (sourcePath, last_line)]) |
662 | 362 | 369 | ||
663 | 363 | 370 | ||
664 | 364 | def test_nonKeywordAfterKeywordSyntaxError(self): | 371 | def test_nonKeywordAfterKeywordSyntaxError(self): |
665 | @@ -371,12 +378,13 @@ | |||
666 | 371 | foo(bar=baz, bax) | 378 | foo(bar=baz, bax) |
667 | 372 | """ | 379 | """ |
668 | 373 | sourcePath = self.makeTempFile(source) | 380 | sourcePath = self.makeTempFile(source) |
669 | 381 | last_line = ' ^\n' if sys.version_info >= (3, 2) else '' | ||
670 | 374 | self.assertHasErrors( | 382 | self.assertHasErrors( |
671 | 375 | sourcePath, | 383 | sourcePath, |
672 | 376 | ["""\ | 384 | ["""\ |
673 | 377 | %s:1: non-keyword arg after keyword arg | 385 | %s:1: non-keyword arg after keyword arg |
674 | 378 | foo(bar=baz, bax) | 386 | foo(bar=baz, bax) |
676 | 379 | """ % (sourcePath,)]) | 387 | %s""" % (sourcePath, last_line)]) |
677 | 380 | 388 | ||
678 | 381 | 389 | ||
679 | 382 | def test_permissionDenied(self): | 390 | def test_permissionDenied(self): |
680 | @@ -405,15 +413,17 @@ | |||
681 | 405 | errors, [('flake', str(UnusedImport(sourcePath, 1, 'foo')))]) | 413 | errors, [('flake', str(UnusedImport(sourcePath, 1, 'foo')))]) |
682 | 406 | 414 | ||
683 | 407 | 415 | ||
684 | 416 | @skipIf(sys.version_info >= (3,), "need adaptation for Python 3") | ||
685 | 408 | def test_misencodedFile(self): | 417 | def test_misencodedFile(self): |
686 | 409 | """ | 418 | """ |
687 | 410 | If a source file contains bytes which cannot be decoded, this is | 419 | If a source file contains bytes which cannot be decoded, this is |
688 | 411 | reported on stderr. | 420 | reported on stderr. |
689 | 412 | """ | 421 | """ |
691 | 413 | source = u"""\ | 422 | SNOWMAN = unichr(0x2603) |
692 | 423 | source = ("""\ | ||
693 | 414 | # coding: ascii | 424 | # coding: ascii |
696 | 415 | x = "\N{SNOWMAN}" | 425 | x = "%s" |
697 | 416 | """.encode('utf-8') | 426 | """ % SNOWMAN).encode('utf-8') |
698 | 417 | sourcePath = self.makeTempFile(source) | 427 | sourcePath = self.makeTempFile(source) |
699 | 418 | self.assertHasErrors( | 428 | self.assertHasErrors( |
700 | 419 | sourcePath, ["%s: problem decoding source\n" % (sourcePath,)]) | 429 | sourcePath, ["%s: problem decoding source\n" % (sourcePath,)]) |
701 | @@ -428,11 +438,11 @@ | |||
702 | 428 | os.mkdir(os.path.join(tempdir, 'foo')) | 438 | os.mkdir(os.path.join(tempdir, 'foo')) |
703 | 429 | file1 = os.path.join(tempdir, 'foo', 'bar.py') | 439 | file1 = os.path.join(tempdir, 'foo', 'bar.py') |
704 | 430 | fd = open(file1, 'wb') | 440 | fd = open(file1, 'wb') |
706 | 431 | fd.write("import baz\n") | 441 | fd.write("import baz\n".encode('ascii')) |
707 | 432 | fd.close() | 442 | fd.close() |
708 | 433 | file2 = os.path.join(tempdir, 'baz.py') | 443 | file2 = os.path.join(tempdir, 'baz.py') |
709 | 434 | fd = open(file2, 'wb') | 444 | fd = open(file2, 'wb') |
711 | 435 | fd.write("import contraband") | 445 | fd.write("import contraband".encode('ascii')) |
712 | 436 | fd.close() | 446 | fd.close() |
713 | 437 | log = [] | 447 | log = [] |
714 | 438 | reporter = LoggingReporter(log) | 448 | reporter = LoggingReporter(log) |
715 | @@ -488,6 +498,9 @@ | |||
716 | 488 | stdout=subprocess.PIPE, stderr=subprocess.PIPE) | 498 | stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
717 | 489 | (stdout, stderr) = p.communicate() | 499 | (stdout, stderr) = p.communicate() |
718 | 490 | rv = p.wait() | 500 | rv = p.wait() |
719 | 501 | if sys.version_info >= (3,): | ||
720 | 502 | stdout = stdout.decode('utf-8') | ||
721 | 503 | stderr = stderr.decode('utf-8') | ||
722 | 491 | return (stdout, stderr, rv) | 504 | return (stdout, stderr, rv) |
723 | 492 | 505 | ||
724 | 493 | 506 | ||
725 | @@ -508,7 +521,7 @@ | |||
726 | 508 | and the warnings are printed to stdout. | 521 | and the warnings are printed to stdout. |
727 | 509 | """ | 522 | """ |
728 | 510 | fd = open(self.tempfilepath, 'wb') | 523 | fd = open(self.tempfilepath, 'wb') |
730 | 511 | fd.write("import contraband\n") | 524 | fd.write("import contraband\n".encode('ascii')) |
731 | 512 | fd.close() | 525 | fd.close() |
732 | 513 | d = self.runPyflakes([self.tempfilepath]) | 526 | d = self.runPyflakes([self.tempfilepath]) |
733 | 514 | self.assertEqual(d, ("%s\n" % UnusedImport(self.tempfilepath, 1, 'contraband'), '', 1)) | 527 | self.assertEqual(d, ("%s\n" % UnusedImport(self.tempfilepath, 1, 'contraband'), '', 1)) |
734 | @@ -528,5 +541,5 @@ | |||
735 | 528 | """ | 541 | """ |
736 | 529 | If no arguments are passed to C{pyflakes} then it reads from stdin. | 542 | If no arguments are passed to C{pyflakes} then it reads from stdin. |
737 | 530 | """ | 543 | """ |
739 | 531 | d = self.runPyflakes([], stdin='import contraband') | 544 | d = self.runPyflakes([], stdin='import contraband'.encode('ascii')) |
740 | 532 | self.assertEqual(d, ("%s\n" % UnusedImport('<stdin>', 1, 'contraband'), '', 1)) | 545 | self.assertEqual(d, ("%s\n" % UnusedImport('<stdin>', 1, 'contraband'), '', 1)) |
741 | 533 | 546 | ||
742 | === modified file 'pyflakes/test/test_undefined_names.py' | |||
743 | --- pyflakes/test/test_undefined_names.py 2013-01-08 16:34:11 +0000 | |||
744 | +++ pyflakes/test/test_undefined_names.py 2013-01-24 10:27:21 +0000 | |||
745 | @@ -1,7 +1,8 @@ | |||
746 | 1 | 1 | ||
747 | 2 | from _ast import PyCF_ONLY_AST | 2 | from _ast import PyCF_ONLY_AST |
748 | 3 | from sys import version_info | ||
749 | 3 | 4 | ||
751 | 4 | from unittest2 import skip, TestCase | 5 | from unittest2 import skip, skipIf, TestCase |
752 | 5 | 6 | ||
753 | 6 | from pyflakes import messages as m, checker | 7 | from pyflakes import messages as m, checker |
754 | 7 | from pyflakes.test import harness | 8 | from pyflakes.test import harness |
755 | @@ -80,6 +81,7 @@ | |||
756 | 80 | bar | 81 | bar |
757 | 81 | ''', m.ImportStarUsed, m.UndefinedName) | 82 | ''', m.ImportStarUsed, m.UndefinedName) |
758 | 82 | 83 | ||
759 | 84 | @skipIf(version_info >= (3,), 'obsolete syntax') | ||
760 | 83 | def test_unpackedParameter(self): | 85 | def test_unpackedParameter(self): |
761 | 84 | '''Unpacked function parameters create bindings''' | 86 | '''Unpacked function parameters create bindings''' |
762 | 85 | self.flakes(''' | 87 | self.flakes(''' |
763 | @@ -102,7 +104,7 @@ | |||
764 | 102 | self.flakes(''' | 104 | self.flakes(''' |
765 | 103 | global x | 105 | global x |
766 | 104 | def foo(): | 106 | def foo(): |
768 | 105 | print x | 107 | print(x) |
769 | 106 | ''', m.UndefinedName) | 108 | ''', m.UndefinedName) |
770 | 107 | 109 | ||
771 | 108 | def test_del(self): | 110 | def test_del(self): |
772 | @@ -176,8 +178,8 @@ | |||
773 | 176 | def h(self): | 178 | def h(self): |
774 | 177 | a = x | 179 | a = x |
775 | 178 | x = None | 180 | x = None |
778 | 179 | print x, a | 181 | print(x, a) |
779 | 180 | print x | 182 | print(x) |
780 | 181 | ''', m.UndefinedLocal) | 183 | ''', m.UndefinedLocal) |
781 | 182 | 184 | ||
782 | 183 | 185 | ||
783 | @@ -246,7 +248,7 @@ | |||
784 | 246 | '''star and double-star arg names are defined''' | 248 | '''star and double-star arg names are defined''' |
785 | 247 | self.flakes(''' | 249 | self.flakes(''' |
786 | 248 | def f(a, *b, **c): | 250 | def f(a, *b, **c): |
788 | 249 | print a, b, c | 251 | print(a, b, c) |
789 | 250 | ''') | 252 | ''') |
790 | 251 | 253 | ||
791 | 252 | def test_definedInGenExp(self): | 254 | def test_definedInGenExp(self): |
792 | @@ -254,7 +256,8 @@ | |||
793 | 254 | Using the loop variable of a generator expression results in no | 256 | Using the loop variable of a generator expression results in no |
794 | 255 | warnings. | 257 | warnings. |
795 | 256 | """ | 258 | """ |
797 | 257 | self.flakes('(a for a in xrange(10) if a)') | 259 | self.flakes('(a for a in %srange(10) if a)' % |
798 | 260 | ('x' if version_info < (3,) else '')) | ||
799 | 258 | 261 | ||
800 | 259 | 262 | ||
801 | 260 | 263 | ||
802 | 261 | 264 | ||
803 | === modified file 'setup.py' | |||
804 | --- setup.py 2011-09-03 16:31:04 +0000 | |||
805 | +++ setup.py 2013-01-24 10:27:21 +0000 | |||
806 | @@ -24,6 +24,8 @@ | |||
807 | 24 | "Intended Audience :: Developers", | 24 | "Intended Audience :: Developers", |
808 | 25 | "License :: OSI Approved :: MIT License", | 25 | "License :: OSI Approved :: MIT License", |
809 | 26 | "Programming Language :: Python", | 26 | "Programming Language :: Python", |
810 | 27 | "Programming Language :: Python :: 2", | ||
811 | 28 | "Programming Language :: Python :: 3", | ||
812 | 27 | "Topic :: Software Development", | 29 | "Topic :: Software Development", |
813 | 28 | "Topic :: Utilities", | 30 | "Topic :: Utilities", |
814 | 29 | ]) | 31 | ]) |