2
2
from _ast import PyCF_ONLY_AST
3
from sys import version_info
4
from twisted.trial.unittest import TestCase
5
from unittest2 import skip, skipIf, TestCase
6
7
from pyflakes import messages as m, checker
7
8
from pyflakes.test import harness
27
28
self.flakes('range(10)')
31
def test_builtinWindowsError(self):
33
C{WindowsError} is sometimes a builtin name, so no warning is emitted
36
self.flakes('WindowsError')
30
39
def test_magicGlobalsFile(self):
32
41
Use of the C{__file__} magic global should not emit an undefined name
73
82
''', m.ImportStarUsed, m.UndefinedName)
84
@skipIf(version_info >= (3,), 'obsolete syntax')
75
85
def test_unpackedParameter(self):
76
86
'''Unpacked function parameters create bindings'''
82
93
def test_definedByGlobal(self):
83
94
'''"global" can make an otherwise undefined name in another function defined'''
85
96
def a(): global fu; fu = 1
88
test_definedByGlobal.todo = ''
90
100
def test_globalInGlobalScope(self):
211
221
''', m.UndefinedLocal)
223
def test_undefinedAugmentedAssignment(self):
237
m.UndefinedName, m.UnusedVariable, # d
213
241
def test_nestedClass(self):
214
242
'''nested classes can access enclosing scope'''
238
266
'''star and double-star arg names are defined'''
240
268
def f(a, *b, **c):
272
@skipIf(version_info < (3,), 'new in Python 3')
273
def test_definedAsStarUnpack(self):
274
'''star names in unpack are defined'''
288
@skipIf(version_info < (3,), 'new in Python 3')
289
def test_keywordOnlyArgs(self):
290
'''kwonly arg names are defined'''
298
def f(*, a, b=default_b):
302
@skipIf(version_info < (3,), 'new in Python 3')
303
def test_keywordOnlyArgsUndefined(self):
304
'''typo in kwonly name'''
306
def f(*, a, b=default_c):
308
''', m.UndefinedName)
310
@skipIf(version_info < (3,), 'new in Python 3')
311
def test_annotationUndefined(self):
312
"""Undefined annotations"""
314
from abc import note1, note2, note3, note4, note5
315
def func(a: note1, *args: note2,
316
b: note3=12, **kw: note4) -> note5: pass
322
def func(a: {1, d}) -> (lambda c: e): pass
325
@skipIf(version_info < (3,), 'new in Python 3')
326
def test_metaClassUndefined(self):
328
from abc import ABCMeta
329
class A(metaclass=ABCMeta): pass
244
332
def test_definedInGenExp(self):
246
334
Using the loop variable of a generator expression results in no
249
self.flakes('(a for a in xrange(10) if a)')
337
self.flakes('(a for a in %srange(10) if a)' %
338
('x' if version_info < (3,) else ''))