gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.app / org.gvsig.scripting.app.mainplugin / src / main / resources-plugin / scripting / lib / pylint / test / functional / undefined_variable_py30.py @ 745
History | View | Annotate | Download (2.1 KB)
1 |
"""Test warnings about access to undefined variables
|
---|---|
2 |
for various Python 3 constructs. """
|
3 |
# pylint: disable=too-few-public-methods, no-init, no-self-use
|
4 |
# pylint: disable=wrong-import-position
|
5 |
class Undefined: |
6 |
""" test various annotation problems. """
|
7 |
|
8 |
def test(self)->Undefined: # [undefined-variable] |
9 |
""" used Undefined, which is Undefined in this scope. """
|
10 |
|
11 |
Undefined = True
|
12 |
|
13 |
def test1(self)->Undefined: |
14 |
""" This Undefined exists at local scope. """
|
15 |
|
16 |
def test2(self): |
17 |
""" This should not emit. """
|
18 |
def func()->Undefined: |
19 |
""" empty """
|
20 |
return
|
21 |
return func
|
22 |
|
23 |
|
24 |
class Undefined1: |
25 |
""" Other annotation problems. """
|
26 |
|
27 |
Undef = 42
|
28 |
ABC = 42
|
29 |
|
30 |
class InnerScope: |
31 |
""" Test inner scope definition. """
|
32 |
|
33 |
def test_undefined(self)->Undef: # [undefined-variable] |
34 |
""" Looking at a higher scope is impossible. """
|
35 |
|
36 |
def test1(self)->ABC: # [undefined-variable] |
37 |
""" Triggers undefined-variable. """
|
38 |
|
39 |
|
40 |
class FalsePositive342(object): |
41 |
# pylint: disable=line-too-long
|
42 |
""" Fix some false positives found in
|
43 |
https://bitbucket.org/logilab/pylint/issue/342/spurious-undefined-variable-for-class
|
44 |
"""
|
45 |
|
46 |
top = 42
|
47 |
|
48 |
def test_good(self, bac: top): |
49 |
""" top is defined at this moment. """
|
50 |
|
51 |
def test_bad(self, bac: trop): # [undefined-variable] |
52 |
""" trop is undefined at this moment. """
|
53 |
|
54 |
def test_bad1(self, *args: trop1): # [undefined-variable] |
55 |
""" trop1 is undefined at this moment. """
|
56 |
|
57 |
def test_bad2(self, **bac: trop2): # [undefined-variable] |
58 |
""" trop2 is undefined at this moment. """
|
59 |
|
60 |
from abc import ABCMeta |
61 |
|
62 |
class Bad(metaclass=ABCMet): # [undefined-variable] |
63 |
""" Notice the typo """
|
64 |
|
65 |
class SecondBad(metaclass=ab.ABCMeta): # [undefined-variable] |
66 |
""" Notice the `ab` module. """
|
67 |
|
68 |
class Good(metaclass=int): |
69 |
""" int is not a proper metaclass, but it is defined. """
|
70 |
|
71 |
class SecondGood(metaclass=Good): |
72 |
""" empty """
|
73 |
|
74 |
class ThirdGood(metaclass=ABCMeta): |
75 |
""" empty """
|
76 |
|
77 |
class FourthGood(ThirdGood): |
78 |
""" This should not trigger anything. """
|