Debian Codegraph @

test/static_analysis/attribute_warnings.py

raw symbols SCIP
1 """
2 Jedi issues warnings for possible errors if ``__getattr__``,
3 ``__getattribute__`` or ``setattr`` are used.
4 """
5
6 # -----------------
7 # __getattr*__
8 # -----------------
9
10
11 class Cls():
12 def __getattr__(self, name):
13 return getattr(str, name)
14
15
16 Cls().upper
17
18 #! 6 warning attribute-error
19 Cls().undefined
20
21
22 class Inherited(Cls):
23 pass
24
25 Inherited().upper
26
27 #! 12 warning attribute-error
28 Inherited().undefined
29
30 # -----------------
31 # setattr
32 # -----------------
33
34
35 class SetattrCls():
36 def __init__(self, dct):
37 # Jedi doesn't even try to understand such code
38 for k, v in dct.items():
39 setattr(self, k, v)
40
41 self.defined = 3
42
43 c = SetattrCls({'a': 'b'})
44 c.defined
45 #! 2 warning attribute-error
46 c.undefined