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

Method reset_init_only_vars

mypy/plugins/dataclasses.py:480–495  ·  view source on GitHub ↗

Remove init-only vars from the class and reset init var declarations.

(self, info: TypeInfo, attributes: list[DataclassAttribute])

Source from the content-addressed store, hash-verified

478 )
479
480 def reset_init_only_vars(self, info: TypeInfo, attributes: list[DataclassAttribute]) -> None:
481 """Remove init-only vars from the class and reset init var declarations."""
482 for attr in attributes:
483 if attr.is_init_var:
484 if attr.name in info.names:
485 del info.names[attr.name]
486 else:
487 # Nodes of superclass InitVars not used in __init__ cannot be reached.
488 assert attr.is_init_var
489 for stmt in info.defn.defs.body:
490 if isinstance(stmt, AssignmentStmt) and stmt.unanalyzed_type:
491 lvalue = stmt.lvalues[0]
492 if isinstance(lvalue, NameExpr) and lvalue.name == attr.name:
493 # Reset node so that another semantic analysis pass will
494 # recreate a symbol node for this attribute.
495 lvalue.node = None
496
497 def _get_assignment_statements_from_if_statement(
498 self, stmt: IfStmt

Callers 1

transformMethod · 0.95

Calls 1

isinstanceFunction · 0.85

Tested by

no test coverage detected