Return whether auto_attribs should be enabled or disabled. It's disabled if there are any unannotated attribs()
(ctx: mypy.plugin.ClassDefContext)
| 508 | |
| 509 | |
| 510 | def _detect_auto_attribs(ctx: mypy.plugin.ClassDefContext) -> bool: |
| 511 | """Return whether auto_attribs should be enabled or disabled. |
| 512 | |
| 513 | It's disabled if there are any unannotated attribs() |
| 514 | """ |
| 515 | for stmt in ctx.cls.defs.body: |
| 516 | if isinstance(stmt, AssignmentStmt): |
| 517 | for lvalue in stmt.lvalues: |
| 518 | lvalues, rvalues = _parse_assignments(lvalue, stmt) |
| 519 | |
| 520 | if len(lvalues) != len(rvalues): |
| 521 | # This means we have some assignment that isn't 1 to 1. |
| 522 | # It can't be an attrib. |
| 523 | continue |
| 524 | |
| 525 | for lhs, rvalue in zip(lvalues, rvalues): |
| 526 | # Check if the right hand side is a call to an attribute maker. |
| 527 | if ( |
| 528 | isinstance(rvalue, CallExpr) |
| 529 | and isinstance(rvalue.callee, RefExpr) |
| 530 | and rvalue.callee.fullname in attr_attrib_makers |
| 531 | and not stmt.new_syntax |
| 532 | ): |
| 533 | # This means we have an attrib without an annotation and so |
| 534 | # we can't do auto_attribs=True |
| 535 | return False |
| 536 | return True |
| 537 | |
| 538 | |
| 539 | def _attributes_from_assignment( |
no test coverage detected
searching dependent graphs…