Skip to content

Commit cbb60d8

Browse files
authored
Support @no_type_check with native parser (#20959)
We apply `@no_type_check` in `fastparse.py` using some (fragile) name matching. A more proper way (which also works for native parser) is to erase annotations during semantic analysis. This fixes half a dozen tests with native parser.
1 parent c32b392 commit cbb60d8

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

mypy/semanal.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1805,6 +1805,8 @@ def visit_decorator(self, dec: Decorator) -> None:
18051805
if (not dec.is_overload or dec.var.is_property) and self.type:
18061806
dec.var.info = self.type
18071807
dec.var.is_initialized_in_class = True
1808+
if no_type_check:
1809+
erase_func_annotations(dec.func)
18081810
if not no_type_check and self.recurse_into_functions:
18091811
dec.func.accept(self)
18101812
if could_be_decorated_property and dec.decorators and dec.var.is_property:
@@ -8353,3 +8355,12 @@ def is_init_only(node: Var) -> bool:
83538355
isinstance(type := get_proper_type(node.type), Instance)
83548356
and type.type.fullname == "dataclasses.InitVar"
83558357
)
8358+
8359+
8360+
def erase_func_annotations(func: FuncDef) -> None:
8361+
func.type_args = None
8362+
for arg in func.arguments:
8363+
arg.type_annotation = None
8364+
arg.variable.type = None
8365+
func.type = None
8366+
func.unanalyzed_type = None

0 commit comments

Comments
 (0)