module documentation
(source)

Plugin for supporting the attrs library (http://www.attrs.org)
Class ​Attribute The value of an attr.ib() call.
Class ​Converter Holds information about a converter= argument
Class ​Method​Adder Helper to add methods to a TypeInfo.
Function attr​_class​_maker​_callback Add necessary dunder methods to classes decorated with attr.s.
Function is​_valid​_overloaded​_converter Undocumented
Constant attr​_attrib​_makers Undocumented
Constant attr​_class​_makers Undocumented
Constant attr​_dataclass​_makers Undocumented
Constant attr​_define​_makers Undocumented
Constant attr​_frozen​_makers Undocumented
Constant KW​_ONLY​_PYTHON​_2​_UNSUPPORTED Undocumented
Constant SELF​_TVAR​_NAME Undocumented
Function _add​_attrs​_magic​_attribute Undocumented
Function _add​_init Generate an __init__ method for the attributes and add it to the class.
Function _add​_order Generate all the ordering methods for this class.
Function _add​_slots Undocumented
Function _analyze​_class Analyze the class body of an attr maker, its parents, and return the Attributes found.
Function _attribute​_from​_attrib​_maker Return an Attribute from the assignment or None if you can't make one.
Function _attribute​_from​_auto​_attrib Return an Attribute for a new type assignment.
Function _attributes​_from​_assignment Return Attribute objects that are created by this assignment.
Function _cleanup​_decorator Handle decorators in class bodies.
Function _detect​_auto​_attribs Return whether auto_attribs should be enabled or disabled.
Function _determine​_eq​_order Validate the combination of cmp, eq, and order. Derive the effective value of order.
Function _get​_decorator​_optional​_bool​_argument Return the Optional[bool] argument for the decorator.
Function _get​_frozen Return whether this class is frozen.
Function _make​_frozen Turn all the attributes into properties to simulate frozen classes.
Function _parse​_assignments Convert a possibly complex assignment expression into lists of lvalues and rvalues.
Function _parse​_converter Return the Converter object from an Expression.
def attr_class_maker_callback(ctx, auto_attribs_default=False, frozen_default=False): (source)

Add necessary dunder methods to classes decorated with attr.s.

attrs is a package that lets you define classes without writing dull boilerplate code.

At a quick glance, the decorator searches the class body for assignments of `attr.ib`s (or annotated variables if auto_attribs=True), then depending on how the decorator is called, it will add an __init__ or all the __cmp__ methods. For frozen=True it will turn the attrs into properties.

See http://www.attrs.org/en/stable/how-does-it-work.html for information on how attrs works.

Parameters
ctx:mypy.plugin.ClassDefContextUndocumented
auto​_attribs​_default:Optional[bool]Undocumented
frozen​_default:boolUndocumented
def is_valid_overloaded_converter(defn): (source)

Undocumented

Parameters
defn:OverloadedFuncDefUndocumented
Returns
boolUndocumented
attr_attrib_makers: set[str] = (source)

Undocumented

Value
set(['attr.ib', 'attr.attrib', 'attr.attr', 'attr.field'])
attr_class_makers: set[str] = (source)

Undocumented

Value
set(['attr.s', 'attr.attrs', 'attr.attributes'])
attr_dataclass_makers: set[str] = (source)

Undocumented

Value
set(['attr.dataclass'])
attr_define_makers: set[str] = (source)

Undocumented

Value
set(['attr.define', 'attr.mutable'])
attr_frozen_makers: set[str] = (source)

Undocumented

Value
set(['attr.frozen'])
KW_ONLY_PYTHON_2_UNSUPPORTED: str = (source)

Undocumented

Value
'kw_only is not supported in Python 2'
SELF_TVAR_NAME: str = (source)

Undocumented

Value
'_AT'
def _add_attrs_magic_attribute(ctx, raw_attr_types): (source)

Undocumented

Parameters
ctx:mypy.plugin.ClassDefContextUndocumented
raw​_attr​_types:List[Optional[Type]]Undocumented
def _add_init(ctx, attributes, adder): (source)
Generate an __init__ method for the attributes and add it to the class.
Parameters
ctx:mypy.plugin.ClassDefContextUndocumented
attributes:List[Attribute]Undocumented
adder:MethodAdderUndocumented
def _add_order(ctx, adder): (source)
Generate all the ordering methods for this class.
Parameters
ctx:mypy.plugin.ClassDefContextUndocumented
adder:MethodAdderUndocumented
def _add_slots(ctx, attributes): (source)

Undocumented

Parameters
ctx:mypy.plugin.ClassDefContextUndocumented
attributes:List[Attribute]Undocumented
def _analyze_class(ctx, auto_attribs, kw_only): (source)

Analyze the class body of an attr maker, its parents, and return the Attributes found.

auto_attribs=True means we'll generate attributes from type annotations also. auto_attribs=None means we'll detect which mode to use. kw_only=True means that all attributes created here will be keyword only args in __init__.

Parameters
ctx:mypy.plugin.ClassDefContextUndocumented
auto​_attribs:Optional[bool]Undocumented
kw​_only:boolUndocumented
Returns
List[Attribute]Undocumented
def _attribute_from_attrib_maker(ctx, auto_attribs, kw_only, lhs, rvalue, stmt): (source)
Return an Attribute from the assignment or None if you can't make one.
Parameters
ctx:mypy.plugin.ClassDefContextUndocumented
auto​_attribs:boolUndocumented
kw​_only:boolUndocumented
lhs:NameExprUndocumented
rvalue:CallExprUndocumented
stmt:AssignmentStmtUndocumented
Returns
Optional[Attribute]Undocumented
def _attribute_from_auto_attrib(ctx, kw_only, lhs, rvalue, stmt): (source)
Return an Attribute for a new type assignment.
Parameters
ctx:mypy.plugin.ClassDefContextUndocumented
kw​_only:boolUndocumented
lhs:NameExprUndocumented
rvalue:ExpressionUndocumented
stmt:AssignmentStmtUndocumented
Returns
AttributeUndocumented
def _attributes_from_assignment(ctx, stmt, auto_attribs, kw_only): (source)

Return Attribute objects that are created by this assignment.

The assignments can look like this:
x = attr.ib() x = y = attr.ib() x, y = attr.ib(), attr.ib()
or if auto_attribs is enabled also like this:
x: type x: type = default_value
Parameters
ctx:mypy.plugin.ClassDefContextUndocumented
stmt:AssignmentStmtUndocumented
auto​_attribs:boolUndocumented
kw​_only:boolUndocumented
Returns
Iterable[Attribute]Undocumented
def _cleanup_decorator(stmt, attr_map): (source)

Handle decorators in class bodies.

x.default will set a default value on x x.validator and x.default will get removed to avoid throwing a type error.

Parameters
stmt:DecoratorUndocumented
attr​_map:Dict[str, Attribute]Undocumented
def _detect_auto_attribs(ctx): (source)

Return whether auto_attribs should be enabled or disabled.

It's disabled if there are any unannotated attribs()

Parameters
ctx:mypy.plugin.ClassDefContextUndocumented
Returns
boolUndocumented
def _determine_eq_order(ctx): (source)
Validate the combination of cmp, eq, and order. Derive the effective value of order.
Parameters
ctx:mypy.plugin.ClassDefContextUndocumented
Returns
boolUndocumented
def _get_decorator_optional_bool_argument(ctx, name, default=None): (source)

Return the Optional[bool] argument for the decorator.

This handles both @decorator(...) and @decorator.

Parameters
ctx:mypy.plugin.ClassDefContextUndocumented
name:strUndocumented
default:Optional[bool]Undocumented
Returns
Optional[bool]Undocumented
def _get_frozen(ctx, frozen_default): (source)
Return whether this class is frozen.
Parameters
ctx:mypy.plugin.ClassDefContextUndocumented
frozen​_default:boolUndocumented
Returns
boolUndocumented
def _make_frozen(ctx, attributes): (source)
Turn all the attributes into properties to simulate frozen classes.
Parameters
ctx:mypy.plugin.ClassDefContextUndocumented
attributes:List[Attribute]Undocumented
def _parse_assignments(lvalue, stmt): (source)
Convert a possibly complex assignment expression into lists of lvalues and rvalues.
Parameters
lvalue:ExpressionUndocumented
stmt:AssignmentStmtUndocumented
Returns
Tuple[List[NameExpr], List[Expression]]Undocumented
def _parse_converter(ctx, converter): (source)
Return the Converter object from an Expression.
Parameters
ctx:mypy.plugin.ClassDefContextUndocumented
converter:Optional[Expression]Undocumented
Returns
ConverterUndocumented