python-static-analysis

Automatically generated description.

Python static analysis

AST.Attribute

Attribute(expr value, identifier attr, expr_context ctx)
expr_context = Load | Store | Del | AugLoad | AugStore | Param

Let’s look what AST would be produced for an “a.b.c” expression:

So, how would we implement semantics of this?

First, we rewind to the first non-attribute node, while saving attribute names on the stack. Then we infer this node into an object. Then we move forward using attribute names from the stack. If the attribute doesn’t exist we should check the context and, if it is “Store”, create a reference to a newly created attribute.

Attribute context

a.b # Load
a.b = 1 # Store
del a.b # Del