Type check a reveal_type expression.
(self, expr: RevealExpr)
| 4856 | return source_type |
| 4857 | |
| 4858 | def visit_reveal_expr(self, expr: RevealExpr) -> Type: |
| 4859 | """Type check a reveal_type expression.""" |
| 4860 | if expr.kind == REVEAL_TYPE: |
| 4861 | assert expr.expr is not None |
| 4862 | revealed_type = self.accept( |
| 4863 | expr.expr, type_context=self.type_context[-1], allow_none_return=True |
| 4864 | ) |
| 4865 | if not self.chk.current_node_deferred: |
| 4866 | self.msg.reveal_type(revealed_type, expr.expr) |
| 4867 | if not self.chk.in_checked_function(): |
| 4868 | self.msg.note( |
| 4869 | "'reveal_type' always outputs 'Any' in unchecked functions", expr.expr |
| 4870 | ) |
| 4871 | self.check_reveal_imported(expr) |
| 4872 | return revealed_type |
| 4873 | else: |
| 4874 | # REVEAL_LOCALS |
| 4875 | if not self.chk.current_node_deferred: |
| 4876 | # the RevealExpr contains a local_nodes attribute, |
| 4877 | # calculated at semantic analysis time. Use it to pull out the |
| 4878 | # corresponding subset of variables in self.chk.type_map |
| 4879 | names_to_types = ( |
| 4880 | {var_node.name: var_node.type for var_node in expr.local_nodes} |
| 4881 | if expr.local_nodes is not None |
| 4882 | else {} |
| 4883 | ) |
| 4884 | |
| 4885 | self.msg.reveal_locals(names_to_types, expr) |
| 4886 | self.check_reveal_imported(expr) |
| 4887 | return NoneType() |
| 4888 | |
| 4889 | def check_reveal_imported(self, expr: RevealExpr) -> None: |
| 4890 | if codes.UNIMPORTED_REVEAL not in self.chk.options.enabled_error_codes: |
nothing calls this directly
no test coverage detected