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 x: type
(
ctx: mypy.plugin.ClassDefContext, stmt: AssignmentStmt, auto_attribs: bool, class_kw_only: bool
)
| 537 | |
| 538 | |
| 539 | def _attributes_from_assignment( |
| 540 | ctx: mypy.plugin.ClassDefContext, stmt: AssignmentStmt, auto_attribs: bool, class_kw_only: bool |
| 541 | ) -> Iterable[Attribute]: |
| 542 | """Return Attribute objects that are created by this assignment. |
| 543 | |
| 544 | The assignments can look like this: |
| 545 | x = attr.ib() |
| 546 | x = y = attr.ib() |
| 547 | x, y = attr.ib(), attr.ib() |
| 548 | or if auto_attribs is enabled also like this: |
| 549 | x: type |
| 550 | x: type = default_value |
| 551 | x: type = attr.ib(...) |
| 552 | """ |
| 553 | for lvalue in stmt.lvalues: |
| 554 | lvalues, rvalues = _parse_assignments(lvalue, stmt) |
| 555 | |
| 556 | if len(lvalues) != len(rvalues): |
| 557 | # This means we have some assignment that isn't 1 to 1. |
| 558 | # It can't be an attrib. |
| 559 | continue |
| 560 | |
| 561 | for lhs, rvalue in zip(lvalues, rvalues): |
| 562 | # Check if the right hand side is a call to an attribute maker. |
| 563 | if ( |
| 564 | isinstance(rvalue, CallExpr) |
| 565 | and isinstance(rvalue.callee, RefExpr) |
| 566 | and rvalue.callee.fullname in attr_attrib_makers |
| 567 | ): |
| 568 | attr = _attribute_from_attrib_maker( |
| 569 | ctx, auto_attribs, class_kw_only, lhs, rvalue, stmt |
| 570 | ) |
| 571 | if attr: |
| 572 | yield attr |
| 573 | elif auto_attribs and stmt.type and stmt.new_syntax and not is_class_var(lhs): |
| 574 | yield _attribute_from_auto_attrib(ctx, class_kw_only, lhs, rvalue, stmt) |
| 575 | |
| 576 | |
| 577 | def _cleanup_decorator(stmt: Decorator, attr_map: dict[str, Attribute]) -> None: |
no test coverage detected
searching dependent graphs…