class documentation

class AbstractAttributeHandler(utils.ContextWeakrefMixin): (source)

View In Hierarchy

Handler for abstract attributes.

Method get_attribute Get the named attribute from the given object.
Method set_attribute Set an attribute on an object.
Method _check_writable Verify that a given attribute is writable. Log an error if not.
Method _computable Undocumented
Method _filter_var Filter the variable by the node.
Method _get_attribute Get an attribute from an object or its class.
Method _get_attribute_computed Call compute_function (if defined) to compute an attribute.
Method _get_attribute_flat Flat attribute retrieval (no mro lookup).
Method _get_attribute_from_super_instance Get an attribute from a super instance.
Method _get_class_attribute Get an attribute from a class.
Method _get_instance_attribute Get an attribute from an instance.
Method _get_member Get a member of an object.
Method _get_module_attribute Get an attribute from a module.
Method _lookup_from_mro Find an identifier in the MRO of the class.
Method _lookup_from_mro_and_handle_descriptors Undocumented
Method _lookup_from_mro_flat Look for an identifier in a single base class from an MRO.
Method _maybe_load_as_instance_attribute Undocumented
Method _set_member Set a member on an object.
Method _should_look_for_submodule Undocumented

Inherited from ContextWeakrefMixin:

Method __init__ Undocumented
Class Variable __slots__ Undocumented
Instance Variable ctx_weakref Undocumented
Property ctx Undocumented
def get_attribute(self, node, obj, name, valself=None): (source)

Get the named attribute from the given object. Args: node: The current CFG node. obj: The object. name: The name of the attribute to retrieve. valself: A cfg.Binding to a self reference to include in the attribute's origins. If obj is an abstract.Class, valself can be a binding to: * an instance of obj - obj will be treated strictly as a class. * obj itself - obj will be treated as an instance of its metaclass. * None - if name == "__getitem__", obj is a type annotation; else, obj is strictly a class, but the attribute is left unbound. Else, valself is optional and should be a binding to obj when given. Returns: A tuple (CFGNode, cfg.Variable). If this attribute doesn't exist, the Variable will be None.

def set_attribute(self, node: cfg.CFGNode, obj: abstract.BaseValue, name: str, value: cfg.Variable) -> cfg.CFGNode: (source)

Set an attribute on an object. The attribute might already have a Variable in it and in that case we cannot overwrite it and instead need to add the elements of the new variable to the old variable. Args: node: The current CFG node. obj: The object. name: The name of the attribute to set. value: The Variable to store in it. Returns: A (possibly changed) CFG node. Raises: AttributeError: If the attribute cannot be set. NotImplementedError: If attribute setting is not implemented for obj.

def _check_writable(self, obj, name): (source)

Verify that a given attribute is writable. Log an error if not.

def _computable(self, name): (source)

Undocumented

def _filter_var(self, node, var): (source)

Filter the variable by the node. Filters the variable data, including recursively expanded type parameter instances, by visibility at the node. A type parameter instance needs to be filtered at the moment of access because its value may change later. Args: node: The current node. var: A variable to filter. Returns: The filtered variable.

def _get_attribute(self, node, obj, cls, name, valself): (source)

Get an attribute from an object or its class. The underlying method called by all of the (_)get_(x_)attribute methods. Attempts to resolve an attribute first with __getattribute__, then by fetching it from the object, then by fetching it from the class, and finally with __getattr__. Arguments: node: The current node. obj: The object. cls: The object's class, may be None. name: The attribute name. valself: The binding to the self reference. Returns: A tuple of the node and the attribute, or None if it was not found.

def _get_attribute_computed(self, node: cfg.CFGNode, cls: Union[abstract.Class, abstract.AmbiguousOrEmptyType], name: str, valself: cfg.Binding, compute_function: str) -> _NodeAndMaybeVarType: (source)

Call compute_function (if defined) to compute an attribute.

def _get_attribute_flat(self, node, cls, name, valself): (source)

Flat attribute retrieval (no mro lookup).

def _get_attribute_from_super_instance(self, node, obj: special_builtins.SuperInstance, name, valself): (source)

Get an attribute from a super instance.

def _get_class_attribute(self, node: cfg.CFGNode, cls: abstract.Class, name: str, valself: Optional[cfg.Binding] = None) -> _NodeAndMaybeVarType: (source)

Get an attribute from a class.

def _get_instance_attribute(self, node: cfg.CFGNode, obj: abstract.SimpleValue, name: str, valself: Optional[cfg.Binding] = None) -> _NodeAndMaybeVarType: (source)

Get an attribute from an instance.

def _get_member(self, node, obj, name, valself): (source)

Get a member of an object.

def _get_module_attribute(self, node: cfg.CFGNode, module: abstract.Module, name: str, valself: Optional[cfg.Binding] = None) -> _NodeAndMaybeVarType: (source)

Get an attribute from a module.

def _lookup_from_mro(self, node, cls, name, valself, skip): (source)

Find an identifier in the MRO of the class.

def _lookup_from_mro_and_handle_descriptors(self, node, cls, name, valself, skip): (source)

Undocumented

def _lookup_from_mro_flat(self, node, base, name, valself, skip): (source)

Look for an identifier in a single base class from an MRO.

def _maybe_load_as_instance_attribute(self, node: cfg.CFGNode, obj: abstract.SimpleValue, name: str): (source)

Undocumented

def _set_member(self, node: cfg.CFGNode, obj: abstract.SimpleValue, name: str, var: cfg.Variable) -> cfg.CFGNode: (source)

Set a member on an object.

def _should_look_for_submodule(self, module: abstract.Module, attr_var: Optional[cfg.Variable]): (source)

Undocumented