module documentation

Base support for generating classes from data declarations. Contains common functionality used by dataclasses, attrs and namedtuples.

Class Decorator Base class for decorators that generate classes from data declarations.
Class FieldConstructor Implements constructors for fields.
Class Ordering Possible orderings for get_class_locals.
Function add_member Undocumented
Function get_class_locals Gets a dictionary of the class's local variables.
Function get_or_create_annotations_dict Get __annotations__ from members map, create and attach it if not present.
Function is_dunder Undocumented
Function is_method Undocumented
Function is_relevant_class_local Tests whether the current class local could be relevant for type checking.
Function make_replace_method Create a replace() method for a dataclass.
Variable log Undocumented
def add_member(node, cls, name, typ): (source)

Undocumented

def get_class_locals(cls_name: str, allow_methods: bool, ordering, ctx): (source)

Gets a dictionary of the class's local variables. Args: cls_name: The name of an abstract.InterpreterClass. allow_methods: A bool, whether to allow methods as variables. ordering: A classgen.Ordering describing the order in which the variables should appear. ctx: The abstract context. Returns: A collections.OrderedDict of the locals.

def get_or_create_annotations_dict(members, ctx): (source)

Get __annotations__ from members map, create and attach it if not present. The returned dict is also referenced by members, so it is safe to mutate. Args: members: A dict of member name to variable. ctx: context.Context instance. Returns: members['__annotations__'] unpacked as a python dict

def is_dunder(name): (source)

Undocumented

def is_method(var): (source)

Undocumented

def is_relevant_class_local(class_local: abstract_utils.Local, class_local_name: str, allow_methods: bool): (source)

Tests whether the current class local could be relevant for type checking. For example, this doesn't match __dunder__ class locals. To get an abstract_utils.Local from a vm.LocalOps, you can use, 'vm_instance.annotated_locals[cls_name][op.name]'. Args: class_local: the local to query class_local_name: the name of the class local (because abstract_utils.Local does not hold this information). allow_methods: whether to allow methods class locals to match Returns: Whether this class local could possibly be relevant for type checking. Callers will usually want to filter even further.

def make_replace_method(ctx, node, cls, *, kwargs_name='kwargs'): (source)

Create a replace() method for a dataclass.

Undocumented