File: attribute_warnings.py

package info (click to toggle)
python-jedi 0.10.0~git1%2Bf05c071-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,064 kB
  • ctags: 3,014
  • sloc: python: 16,997; makefile: 149; ansic: 13
file content (46 lines) | stat: -rw-r--r-- 746 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""
Jedi issues warnings for possible errors if ``__getattr__``,
``__getattribute__`` or ``setattr`` are used.
"""

# -----------------
# __getattr*__
# -----------------


class Cls():
    def __getattr__(self, name):
        return getattr(str, name)


Cls().upper

#! 6 warning attribute-error
Cls().undefined


class Inherited(Cls):
    pass

Inherited().upper

#! 12 warning attribute-error
Inherited().undefined

# -----------------
# setattr
# -----------------


class SetattrCls():
    def __init__(self, dct):
        # Jedi doesn't even try to understand such code
        for k, v in dct.items():
            setattr(self, k, v)

        self.defined = 3

c = SetattrCls({'a': 'b'})
c.defined
#! 2 warning attribute-error
c.undefined