Analyze a call expression. Some call expressions are recognized as special forms, including cast(...).
(self, expr: CallExpr)
| 5917 | e.expr.accept(self) |
| 5918 | |
| 5919 | def visit_call_expr(self, expr: CallExpr) -> None: |
| 5920 | """Analyze a call expression. |
| 5921 | |
| 5922 | Some call expressions are recognized as special forms, including |
| 5923 | cast(...). |
| 5924 | """ |
| 5925 | expr.callee.accept(self) |
| 5926 | if refers_to_fullname(expr.callee, "typing.cast"): |
| 5927 | # Special form cast(...). |
| 5928 | if not self.check_fixed_args(expr, 2, "cast"): |
| 5929 | return |
| 5930 | # Translate first argument to an unanalyzed type. |
| 5931 | try: |
| 5932 | target = self.expr_to_unanalyzed_type(expr.args[0]) |
| 5933 | except TypeTranslationError: |
| 5934 | self.fail("Cast target is not a type", expr) |
| 5935 | return |
| 5936 | # Piggyback CastExpr object to the CallExpr object; it takes |
| 5937 | # precedence over the CallExpr semantics. |
| 5938 | expr.analyzed = CastExpr(expr.args[1], target) |
| 5939 | expr.analyzed.line = expr.line |
| 5940 | expr.analyzed.column = expr.column |
| 5941 | expr.analyzed.accept(self) |
| 5942 | elif refers_to_fullname(expr.callee, ASSERT_TYPE_NAMES): |
| 5943 | if not self.check_fixed_args(expr, 2, "assert_type"): |
| 5944 | return |
| 5945 | # Translate second argument to an unanalyzed type. |
| 5946 | try: |
| 5947 | target = self.expr_to_unanalyzed_type(expr.args[1]) |
| 5948 | except TypeTranslationError: |
| 5949 | self.fail("assert_type() type is not a type", expr) |
| 5950 | return |
| 5951 | expr.analyzed = AssertTypeExpr(expr.args[0], target) |
| 5952 | expr.analyzed.line = expr.line |
| 5953 | expr.analyzed.column = expr.column |
| 5954 | expr.analyzed.accept(self) |
| 5955 | elif refers_to_fullname(expr.callee, REVEAL_TYPE_NAMES): |
| 5956 | if not self.check_fixed_args(expr, 1, "reveal_type"): |
| 5957 | return |
| 5958 | reveal_imported = False |
| 5959 | reveal_type_node = self.lookup("reveal_type", expr, suppress_errors=True) |
| 5960 | if ( |
| 5961 | reveal_type_node |
| 5962 | and isinstance(reveal_type_node.node, SYMBOL_FUNCBASE_TYPES) |
| 5963 | and reveal_type_node.fullname in IMPORTED_REVEAL_TYPE_NAMES |
| 5964 | ): |
| 5965 | reveal_imported = True |
| 5966 | expr.analyzed = RevealExpr( |
| 5967 | kind=REVEAL_TYPE, expr=expr.args[0], is_imported=reveal_imported |
| 5968 | ) |
| 5969 | expr.analyzed.line = expr.line |
| 5970 | expr.analyzed.column = expr.column |
| 5971 | expr.analyzed.accept(self) |
| 5972 | elif refers_to_fullname(expr.callee, "builtins.reveal_locals"): |
| 5973 | # Store the local variable names into the RevealExpr for use in the |
| 5974 | # type checking pass |
| 5975 | local_nodes: list[Var] = [] |
| 5976 | if self.is_module_scope(): |
nothing calls this directly
no test coverage detected