MCPcopy Index your code
hub / github.com/python/mypy / _detect_auto_attribs

Function _detect_auto_attribs

mypy/plugins/attrs.py:510–536  ·  view source on GitHub ↗

Return whether auto_attribs should be enabled or disabled. It's disabled if there are any unannotated attribs()

(ctx: mypy.plugin.ClassDefContext)

Source from the content-addressed store, hash-verified

508
509
510def _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
539def _attributes_from_assignment(

Callers 1

_analyze_classFunction · 0.85

Calls 4

isinstanceFunction · 0.85
_parse_assignmentsFunction · 0.85
lenFunction · 0.85
zipFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…