(self, o: AssignmentStmt)
| 962 | super().visit_block(o) |
| 963 | |
| 964 | def visit_assignment_stmt(self, o: AssignmentStmt) -> None: |
| 965 | foundl = [] |
| 966 | |
| 967 | for lvalue in o.lvalues: |
| 968 | if isinstance(lvalue, NameExpr) and isinstance(o.rvalue, CallExpr): |
| 969 | if self.is_namedtuple(o.rvalue) or self.is_typed_namedtuple(o.rvalue): |
| 970 | self.process_namedtuple(lvalue, o.rvalue) |
| 971 | foundl.append(False) # state is updated in process_namedtuple |
| 972 | continue |
| 973 | if self.is_typeddict(o.rvalue): |
| 974 | self.process_typeddict(lvalue, o.rvalue) |
| 975 | foundl.append(False) # state is updated in process_typeddict |
| 976 | continue |
| 977 | if ( |
| 978 | isinstance(lvalue, NameExpr) |
| 979 | and self.is_alias_expression(o.rvalue) |
| 980 | and not self.is_private_name(lvalue.name) |
| 981 | ): |
| 982 | is_explicit_type_alias = ( |
| 983 | o.unanalyzed_type and getattr(o.type, "name", None) == "TypeAlias" |
| 984 | ) |
| 985 | if is_explicit_type_alias: |
| 986 | self.process_typealias(lvalue, o.rvalue, is_explicit_type_alias=True) |
| 987 | continue |
| 988 | |
| 989 | if not o.unanalyzed_type: |
| 990 | self.process_typealias(lvalue, o.rvalue) |
| 991 | continue |
| 992 | |
| 993 | if isinstance(lvalue, (TupleExpr, ListExpr)): |
| 994 | items = lvalue.items |
| 995 | if isinstance(o.unanalyzed_type, TupleType): # type: ignore[misc] |
| 996 | annotations: Iterable[Type | None] = o.unanalyzed_type.items |
| 997 | else: |
| 998 | annotations = [None] * len(items) |
| 999 | else: |
| 1000 | items = [lvalue] |
| 1001 | annotations = [o.unanalyzed_type] |
| 1002 | sep = False |
| 1003 | found = False |
| 1004 | for item, annotation in zip(items, annotations): |
| 1005 | if isinstance(item, NameExpr): |
| 1006 | init = self.get_init(item.name, o.rvalue, annotation) |
| 1007 | if init: |
| 1008 | found = True |
| 1009 | if not sep and self.is_top_level() and self._state not in (EMPTY, VAR): |
| 1010 | init = "\n" + init |
| 1011 | sep = True |
| 1012 | self.add(init) |
| 1013 | self.record_name(item.name) |
| 1014 | foundl.append(found) |
| 1015 | |
| 1016 | if all(foundl): |
| 1017 | self._state = VAR |
| 1018 | |
| 1019 | def is_namedtuple(self, expr: CallExpr) -> bool: |
| 1020 | return self.get_fullname(expr.callee) == "collections.namedtuple" |
nothing calls this directly
no test coverage detected