Plugin for supporting the attrs library (http://www.attrs.org)
Class |
|
The value of an attr.ib() call. |
Class |
|
Holds information about a `converter=` argument |
Class |
|
Helper to add methods to a TypeInfo. |
Function | attr |
Add necessary dunder methods to classes decorated with attr.s. |
Function | attr |
Record that we have an attrs class in the main semantic analysis pass. |
Function | is |
Undocumented |
Constant | attr |
Undocumented |
Constant | attr |
Undocumented |
Constant | attr |
Undocumented |
Constant | attr |
Undocumented |
Constant | attr |
Undocumented |
Constant | attr |
Undocumented |
Constant | MAGIC |
Undocumented |
Constant | MAGIC |
Undocumented |
Constant | SELF |
Undocumented |
Function | _add |
Undocumented |
Function | _add |
Add empty metadata to mark that we've finished processing this class. |
Function | _add |
Generate an __init__ method for the attributes and add it to the class. |
Function | _add |
Undocumented |
Function | _add |
Generate all the ordering methods for this class. |
Function | _add |
Undocumented |
Function | _analyze |
Analyze the class body of an attr maker, its parents, and return the Attributes found. |
Function | _attribute |
Return an Attribute from the assignment or None if you can't make one. |
Function | _attribute |
Return an Attribute for a new type assignment. |
Function | _attributes |
Return Attribute objects that are created by this assignment. |
Function | _cleanup |
Handle decorators in class bodies. |
Function | _detect |
Return whether auto_attribs should be enabled or disabled. |
Function | _determine |
Validate the combination of *cmp*, *eq*, and *order*. Derive the effective value of order. |
Function | _get |
Return the Optional[bool] argument for the decorator. |
Function | _get |
Return whether this class is frozen. |
Function | _make |
Turn all the attributes into properties to simulate frozen classes. |
Function | _parse |
Convert a possibly complex assignment expression into lists of lvalues and rvalues. |
Function | _parse |
Return the Converter object from an Expression. |
mypy.plugin.ClassDefContext
, auto_attribs_default: bool|None
= False, frozen_default: bool
= False) -> bool
:
(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 compare 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. If this returns False, some required metadata was not ready yet and we need another pass.
Record that we have an attrs class in the main semantic analysis pass. The later pass implemented by attr_class_maker_callback will use this to detect attrs classes in base classes.
mypy.plugin.ClassDefContext
, attrs: list[ tuple[ str, Type|None]]
):
(source)
¶
Undocumented
mypy.plugin.ClassDefContext
, attributes: list[ Attribute]
, adder: MethodAdder
, method_name: Literal[ '__init__', '__attrs_init__']
):
(source)
¶
Generate an __init__ method for the attributes and add it to the class.
mypy.plugin.ClassDefContext
, auto_attribs: bool|None
, kw_only: bool
) -> list[ Attribute]
:
(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__.
mypy.plugin.ClassDefContext
, auto_attribs: bool
, kw_only: bool
, lhs: NameExpr
, rvalue: CallExpr
, stmt: AssignmentStmt
) -> Attribute|None
:
(source)
¶
Return an Attribute from the assignment or None if you can't make one.
mypy.plugin.ClassDefContext
, kw_only: bool
, lhs: NameExpr
, rvalue: Expression
, stmt: AssignmentStmt
) -> Attribute
:
(source)
¶
Return an Attribute for a new type assignment.
mypy.plugin.ClassDefContext
, stmt: AssignmentStmt
, auto_attribs: bool
, kw_only: bool
) -> Iterable[ Attribute]
:
(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
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.
Return whether auto_attribs should be enabled or disabled. It's disabled if there are any unannotated attribs()
mypy.plugin.ClassDefContext
, name: str
, default: bool|None
= None) -> bool|None
:
(source)
¶
Return the Optional[bool] argument for the decorator. This handles both @decorator(...) and @decorator.
Expression
, stmt: AssignmentStmt
) -> tuple[ list[ NameExpr], list[ Expression]]
:
(source)
¶
Convert a possibly complex assignment expression into lists of lvalues and rvalues.
mypy.plugin.ClassDefContext
, converter_expr: Expression|None
) -> Converter|None
:
(source)
¶
Return the Converter object from an Expression.