Directly set the narrowed type of expression (if it supports it). This is used for isinstance() etc. Assignments should go through assign_type().
(self, expr: Expression, typ: Type, *, from_assignment: bool = True)
| 248 | return isinstance(expr, (IndexExpr, MemberExpr, NameExpr)) and literal(expr) > LITERAL_NO |
| 249 | |
| 250 | def put(self, expr: Expression, typ: Type, *, from_assignment: bool = True) -> None: |
| 251 | """Directly set the narrowed type of expression (if it supports it). |
| 252 | |
| 253 | This is used for isinstance() etc. Assignments should go through assign_type(). |
| 254 | """ |
| 255 | if not isinstance(expr, (IndexExpr, MemberExpr, NameExpr)): |
| 256 | return |
| 257 | if not literal(expr): |
| 258 | return |
| 259 | key = literal_hash(expr) |
| 260 | assert key is not None, "Internal error: binder tried to put non-literal" |
| 261 | if key not in self.declarations: |
| 262 | self.declarations[key] = get_declaration(expr) |
| 263 | self._add_dependencies(key) |
| 264 | self._put(key, typ, from_assignment) |
| 265 | |
| 266 | def unreachable(self) -> None: |
| 267 | self.version += 1 |