diff --git a/mypy/build.py b/mypy/build.py index 79846a1032b7..01bc80c2fe81 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -835,6 +835,8 @@ def parse_file( Raise CompileError if there is a parse error. """ t0 = time.time() + if ignore_errors: + self.errors.ignored_files.add(path) tree = parse(source, path, id, self.errors, options=options) tree._fullname = id self.add_stats( diff --git a/mypy/config_parser.py b/mypy/config_parser.py index c723f99770c9..05af2ba6e21e 100644 --- a/mypy/config_parser.py +++ b/mypy/config_parser.py @@ -538,10 +538,7 @@ def split_directive(s: str) -> tuple[list[str], list[str]]: def mypy_comments_to_config_map(line: str, template: Options) -> tuple[dict[str, str], list[str]]: - """Rewrite the mypy comment syntax into ini file syntax. - - Returns - """ + """Rewrite the mypy comment syntax into ini file syntax.""" options = {} entries, errors = split_directive(line) for entry in entries: diff --git a/mypy/fastparse.py b/mypy/fastparse.py index 14799214ca6b..9300912fceca 100644 --- a/mypy/fastparse.py +++ b/mypy/fastparse.py @@ -99,6 +99,7 @@ ) from mypy.reachability import infer_reachability_of_if_statement, mark_block_unreachable from mypy.sharedparse import argument_elide_name, special_function_elide_names +from mypy.traverser import TraverserVisitor from mypy.types import ( AnyType, CallableArgument, @@ -260,6 +261,11 @@ def parse( Return the parse tree. If errors is not provided, raise ParseError on failure. Otherwise, use the errors object to report parse errors. """ + ignore_errors = (options is not None and options.ignore_errors) or ( + errors is not None and fnam in errors.ignored_files + ) + # If errors are ignored, we can drop many function bodies to speed up type checking. + strip_function_bodies = ignore_errors and (options is None or not options.preserve_asts) raise_on_error = False if options is None: options = Options() @@ -281,7 +287,13 @@ def parse( warnings.filterwarnings("ignore", category=DeprecationWarning) ast = ast3_parse(source, fnam, "exec", feature_version=feature_version) - tree = ASTConverter(options=options, is_stub=is_stub_file, errors=errors).visit(ast) + tree = ASTConverter( + options=options, + is_stub=is_stub_file, + errors=errors, + ignore_errors=ignore_errors, + strip_function_bodies=strip_function_bodies, + ).visit(ast) tree.path = fnam tree.is_stub = is_stub_file except SyntaxError as e: @@ -400,14 +412,24 @@ def is_no_type_check_decorator(expr: ast3.expr) -> bool: class ASTConverter: - def __init__(self, options: Options, is_stub: bool, errors: Errors) -> None: - # 'C' for class, 'F' for function - self.class_and_function_stack: list[Literal["C", "F"]] = [] + def __init__( + self, + options: Options, + is_stub: bool, + errors: Errors, + *, + ignore_errors: bool, + strip_function_bodies: bool, + ) -> None: + # 'C' for class, 'D' for function signature, 'F' for function, 'L' for lambda + self.class_and_function_stack: list[Literal["C", "D", "F", "L"]] = [] self.imports: list[ImportBase] = [] self.options = options self.is_stub = is_stub self.errors = errors + self.ignore_errors = ignore_errors + self.strip_function_bodies = strip_function_bodies self.type_ignores: dict[int, list[str]] = {} @@ -475,7 +497,12 @@ def get_lineno(self, node: ast3.expr | ast3.stmt) -> int: return node.lineno def translate_stmt_list( - self, stmts: Sequence[ast3.stmt], ismodule: bool = False + self, + stmts: Sequence[ast3.stmt], + *, + ismodule: bool = False, + can_strip: bool = False, + is_coroutine: bool = False, ) -> list[Statement]: # A "# type: ignore" comment before the first statement of a module # ignores the whole module: @@ -504,11 +531,41 @@ def translate_stmt_list( mark_block_unreachable(block) return [block] + stack = self.class_and_function_stack + if self.strip_function_bodies and len(stack) == 1 and stack[0] == "F": + return [] + res: list[Statement] = [] for stmt in stmts: node = self.visit(stmt) res.append(node) + if ( + self.strip_function_bodies + and can_strip + and stack[-2:] == ["C", "F"] + and not is_possible_trivial_body(res) + ): + # We only strip method bodies if they don't assign to an attribute, as + # this may define an attribute which has an externally visible effect. + visitor = FindAttributeAssign() + for s in res: + s.accept(visitor) + if visitor.found: + break + else: + if is_coroutine: + # Yields inside an async function affect the return type and should not + # be stripped. + yield_visitor = FindYield() + for s in res: + s.accept(yield_visitor) + if yield_visitor.found: + break + else: + return [] + else: + return [] return res def translate_type_comment( @@ -573,9 +630,20 @@ def as_block(self, stmts: list[ast3.stmt], lineno: int) -> Block | None: b.set_line(lineno) return b - def as_required_block(self, stmts: list[ast3.stmt], lineno: int) -> Block: + def as_required_block( + self, + stmts: list[ast3.stmt], + lineno: int, + *, + can_strip: bool = False, + is_coroutine: bool = False, + ) -> Block: assert stmts # must be non-empty - b = Block(self.fix_function_overloads(self.translate_stmt_list(stmts))) + b = Block( + self.fix_function_overloads( + self.translate_stmt_list(stmts, can_strip=can_strip, is_coroutine=is_coroutine) + ) + ) # TODO: in most call sites line is wrong (includes first line of enclosing statement) # TODO: also we need to set the column, and the end position here. b.set_line(lineno) @@ -831,9 +899,6 @@ def _is_stripped_if_stmt(self, stmt: Statement) -> bool: # For elif, IfStmt are stored recursively in else_body return self._is_stripped_if_stmt(stmt.else_body.body[0]) - def in_method_scope(self) -> bool: - return self.class_and_function_stack[-2:] == ["C", "F"] - def translate_module_id(self, id: str) -> str: """Return the actual, internal module id for a source text id.""" if id == self.options.custom_typing_module: @@ -868,7 +933,7 @@ def do_func_def( self, n: ast3.FunctionDef | ast3.AsyncFunctionDef, is_coroutine: bool = False ) -> FuncDef | Decorator: """Helper shared between visit_FunctionDef and visit_AsyncFunctionDef.""" - self.class_and_function_stack.append("F") + self.class_and_function_stack.append("D") no_type_check = bool( n.decorator_list and any(is_no_type_check_decorator(d) for d in n.decorator_list) ) @@ -915,7 +980,8 @@ def do_func_def( return_type = TypeConverter(self.errors, line=lineno).visit(func_type_ast.returns) # add implicit self type - if self.in_method_scope() and len(arg_types) < len(args): + in_method_scope = self.class_and_function_stack[-2:] == ["C", "D"] + if in_method_scope and len(arg_types) < len(args): arg_types.insert(0, AnyType(TypeOfAny.special_form)) except SyntaxError: stripped_type = n.type_comment.split("#", 2)[0].strip() @@ -965,7 +1031,10 @@ def do_func_def( end_line = getattr(n, "end_lineno", None) end_column = getattr(n, "end_col_offset", None) - func_def = FuncDef(n.name, args, self.as_required_block(n.body, lineno), func_type) + self.class_and_function_stack.pop() + self.class_and_function_stack.append("F") + body = self.as_required_block(n.body, lineno, can_strip=True, is_coroutine=is_coroutine) + func_def = FuncDef(n.name, args, body, func_type) if isinstance(func_def.type, CallableType): # semanal.py does some in-place modifications we want to avoid func_def.unanalyzed_type = func_def.type.copy_modified() @@ -1409,9 +1478,11 @@ def visit_Lambda(self, n: ast3.Lambda) -> LambdaExpr: body.lineno = n.body.lineno body.col_offset = n.body.col_offset + self.class_and_function_stack.append("L") e = LambdaExpr( self.transform_args(n.args, n.lineno), self.as_required_block([body], n.lineno) ) + self.class_and_function_stack.pop() e.set_line(n.lineno, n.col_offset) # Overrides set_line -- can't use self.set_line return e @@ -2081,3 +2152,85 @@ def stringify_name(n: AST) -> str | None: if sv is not None: return f"{sv}.{n.attr}" return None # Can't do it. + + +class FindAttributeAssign(TraverserVisitor): + """Check if an AST contains attribute assignments (e.g. self.x = 0).""" + + def __init__(self) -> None: + self.lvalue = False + self.found = False + + def visit_assignment_stmt(self, s: AssignmentStmt) -> None: + self.lvalue = True + for lv in s.lvalues: + lv.accept(self) + self.lvalue = False + + def visit_with_stmt(self, s: WithStmt) -> None: + self.lvalue = True + for lv in s.target: + if lv is not None: + lv.accept(self) + self.lvalue = False + s.body.accept(self) + + def visit_for_stmt(self, s: ForStmt) -> None: + self.lvalue = True + s.index.accept(self) + self.lvalue = False + s.body.accept(self) + if s.else_body: + s.else_body.accept(self) + + def visit_expression_stmt(self, s: ExpressionStmt) -> None: + # No need to look inside these + pass + + def visit_call_expr(self, e: CallExpr) -> None: + # No need to look inside these + pass + + def visit_index_expr(self, e: IndexExpr) -> None: + # No need to look inside these + pass + + def visit_member_expr(self, e: MemberExpr) -> None: + if self.lvalue: + self.found = True + + +class FindYield(TraverserVisitor): + """Check if an AST contains yields or yield froms.""" + + def __init__(self) -> None: + self.found = False + + def visit_yield_expr(self, e: YieldExpr) -> None: + self.found = True + + def visit_yield_from_expr(self, e: YieldFromExpr) -> None: + self.found = True + + +def is_possible_trivial_body(s: list[Statement]) -> bool: + """Could the statements form a "trivial" function body, such as 'pass'? + + This mimics mypy.semanal.is_trivial_body, but this runs before + semantic analysis so some checks must be conservative. + """ + l = len(s) + if l == 0: + return False + i = 0 + if isinstance(s[0], ExpressionStmt) and isinstance(s[0].expr, StrExpr): + # Skip docstring + i += 1 + if i == l: + return True + if l > i + 1: + return False + stmt = s[i] + return isinstance(stmt, (PassStmt, RaiseStmt)) or ( + isinstance(stmt, ExpressionStmt) and isinstance(stmt.expr, EllipsisExpr) + ) diff --git a/mypy/semanal.py b/mypy/semanal.py index 8d17c84b130b..ad470fbfd9de 100644 --- a/mypy/semanal.py +++ b/mypy/semanal.py @@ -6684,7 +6684,7 @@ def is_trivial_body(block: Block) -> bool: "..." (ellipsis), or "raise NotImplementedError()". A trivial body may also start with a statement containing just a string (e.g. a docstring). - Note: functions that raise other kinds of exceptions do not count as + Note: Functions that raise other kinds of exceptions do not count as "trivial". We use this function to help us determine when it's ok to relax certain checks on body, but functions that raise arbitrary exceptions are more likely to do non-trivial work. For example: @@ -6694,11 +6694,18 @@ def halt(self, reason: str = ...) -> NoReturn: A function that raises just NotImplementedError is much less likely to be this complex. + + Note: If you update this, you may also need to update + mypy.fastparse.is_possible_trivial_body! """ body = block.body + if not body: + # Functions have empty bodies only if the body is stripped or the function is + # generated or deserialized. In these cases the body is unknown. + return False # Skip a docstring - if body and isinstance(body[0], ExpressionStmt) and isinstance(body[0].expr, StrExpr): + if isinstance(body[0], ExpressionStmt) and isinstance(body[0].expr, StrExpr): body = block.body[1:] if len(body) == 0: diff --git a/mypy/stubgen.py b/mypy/stubgen.py index c13096189f7e..84b2e721be9c 100755 --- a/mypy/stubgen.py +++ b/mypy/stubgen.py @@ -1588,6 +1588,7 @@ def mypy_options(stubgen_options: Options) -> MypyOptions: options.python_version = stubgen_options.pyversion options.show_traceback = True options.transform_source = remove_misplaced_type_comments + options.preserve_asts = True return options diff --git a/mypy/test/testparse.py b/mypy/test/testparse.py index 3fc88277e01b..0140eb072821 100644 --- a/mypy/test/testparse.py +++ b/mypy/test/testparse.py @@ -7,11 +7,13 @@ from pytest import skip from mypy import defaults +from mypy.config_parser import parse_mypy_comments from mypy.errors import CompileError from mypy.options import Options from mypy.parse import parse from mypy.test.data import DataDrivenTestCase, DataSuite from mypy.test.helpers import assert_string_arrays_equal, find_test_files, parse_options +from mypy.util import get_mypy_comments class ParserSuite(DataSuite): @@ -40,13 +42,16 @@ def test_parser(testcase: DataDrivenTestCase) -> None: else: options.python_version = defaults.PYTHON3_VERSION + source = "\n".join(testcase.input) + + # Apply mypy: comments to options. + comments = get_mypy_comments(source) + changes, _ = parse_mypy_comments(comments, options) + options = options.apply_changes(changes) + try: n = parse( - bytes("\n".join(testcase.input), "ascii"), - fnam="main", - module="__main__", - errors=None, - options=options, + bytes(source, "ascii"), fnam="main", module="__main__", errors=None, options=options ) a = n.str_with_options(options).split("\n") except CompileError as e: diff --git a/test-data/unit/check-async-await.test b/test-data/unit/check-async-await.test index 7356fa59c86d..c9b400520af6 100644 --- a/test-data/unit/check-async-await.test +++ b/test-data/unit/check-async-await.test @@ -944,6 +944,49 @@ async def bar(x: Union[A, B]) -> None: [builtins fixtures/async_await.pyi] [typing fixtures/typing-async.pyi] +[case testAsyncIteratorWithIgnoredErrors] +from m import L + +async def func(l: L) -> None: + reveal_type(l.get_iterator) # N: Revealed type is "def () -> typing.AsyncIterator[builtins.str]" + reveal_type(l.get_iterator2) # N: Revealed type is "def () -> typing.AsyncIterator[builtins.str]" + async for i in l.get_iterator(): + reveal_type(i) # N: Revealed type is "builtins.str" + +[file m.py] +# mypy: ignore-errors=True +from typing import AsyncIterator + +class L: + async def some_func(self, i: int) -> str: + return 'x' + + async def get_iterator(self) -> AsyncIterator[str]: + yield await self.some_func(0) + + async def get_iterator2(self) -> AsyncIterator[str]: + if self: + a = (yield 'x') + +[builtins fixtures/async_await.pyi] +[typing fixtures/typing-async.pyi] + +[case testAsyncIteratorWithIgnoredErrorsAndYieldFrom] +from m import L + +async def func(l: L) -> None: + reveal_type(l.get_iterator) + +[file m.py] +# mypy: ignore-errors=True +from typing import AsyncIterator + +class L: + async def get_iterator(self) -> AsyncIterator[str]: + yield from ['x'] # E: "yield from" in async function +[builtins fixtures/async_await.pyi] +[typing fixtures/typing-async.pyi] + [case testInvalidComprehensionNoCrash] # flags: --show-error-codes async def foo(x: int) -> int: ... diff --git a/test-data/unit/check-inline-config.test b/test-data/unit/check-inline-config.test index ee847deabd40..db04536dd4f9 100644 --- a/test-data/unit/check-inline-config.test +++ b/test-data/unit/check-inline-config.test @@ -211,6 +211,111 @@ enable_error_code = ignore-without-code, truthy-bool \[mypy-tests.*] disable_error_code = ignore-without-code +[case testIgnoreErrorsSimple] +# mypy: ignore-errors=True + +def f() -> None: + while 1(): + pass + +[case testIgnoreErrorsInImportedModule] +from m import C +c = C() +reveal_type(c.x) # N: Revealed type is "builtins.int" + +[file m.py] +# mypy: ignore-errors=True + +class C: + def f(self) -> None: + self.x = 1 + +[case testIgnoreErrorsWithLambda] +# mypy: ignore-errors=True + +def f(self, x=lambda: 1) -> None: + pass + +class C: + def f(self) -> None: + l = lambda: 1 + self.x = 1 + +[case testIgnoreErrorsWithUnsafeSuperCall_no_empty] +# flags: --strict-optional + +from m import C + +class D(C): + def m(self) -> None: + super().m1() + super().m2() \ + # E: Call to abstract method "m2" of "C" with trivial body via super() is unsafe + super().m3() \ + # E: Call to abstract method "m3" of "C" with trivial body via super() is unsafe + super().m4() \ + # E: Call to abstract method "m4" of "C" with trivial body via super() is unsafe + super().m5() \ + # E: Call to abstract method "m5" of "C" with trivial body via super() is unsafe + super().m6() \ + # E: Call to abstract method "m6" of "C" with trivial body via super() is unsafe + super().m7() + + def m1(self) -> int: + return 0 + + def m2(self) -> int: + return 0 + + def m3(self) -> int: + return 0 + + def m4(self) -> int: + return 0 + + def m5(self) -> int: + return 0 + + def m6(self) -> int: + return 0 + +[file m.py] +# mypy: ignore-errors=True +import abc + +class C: + @abc.abstractmethod + def m1(self) -> int: + """x""" + return 0 + + @abc.abstractmethod + def m2(self) -> int: + """doc""" + + @abc.abstractmethod + def m3(self) -> int: + pass + + @abc.abstractmethod + def m4(self) -> int: ... + + @abc.abstractmethod + def m5(self) -> int: + """doc""" + ... + + @abc.abstractmethod + def m6(self) -> int: + raise NotImplementedError() + + @abc.abstractmethod + def m7(self) -> int: + raise NotImplementedError() + pass + +[builtins fixtures/exception.pyi] + [case testInlineErrorCodesMultipleCodes] # mypy: disable-error-code="truthy-bool, ignore-without-code" class Foo: diff --git a/test-data/unit/parse.test b/test-data/unit/parse.test index ff892ce0ce05..22ebf31a7dbe 100644 --- a/test-data/unit/parse.test +++ b/test-data/unit/parse.test @@ -95,7 +95,6 @@ MypyFile:1( StrExpr(x\n\')) ExpressionStmt:2( StrExpr(x\n\"))) ---" fix syntax highlight [case testBytes] b'foo' @@ -128,7 +127,6 @@ MypyFile:1( MypyFile:1( ExpressionStmt:1( StrExpr('))) ---' [case testOctalEscapes] '\0\1\177\1234' @@ -3484,3 +3482,358 @@ MypyFile:1( NameExpr(y) NameExpr(y)) StrExpr())))))))))))) + +[case testStripFunctionBodiesIfIgnoringErrors] +# mypy: ignore-errors=True +def f(self): + self.x = 1 # Cannot define an attribute + return 1 +[out] +MypyFile:1( + FuncDef:2( + f + Args( + Var(self)) + Block:2())) + +[case testStripMethodBodiesIfIgnoringErrors] +# mypy: ignore-errors=True +class C: + def f(self): + x = self.x + for x in y: + pass + with a as y: + pass + while self.foo(): + self.bah() + a[self.x] = 1 +[out] +MypyFile:1( + ClassDef:2( + C + FuncDef:3( + f + Args( + Var(self)) + Block:3()))) + +[case testDoNotStripModuleTopLevelOrClassBody] +# mypy: ignore-errors=True +f() +class C: + x = 5 +[out] +MypyFile:1( + ExpressionStmt:2( + CallExpr:2( + NameExpr(f) + Args())) + ClassDef:3( + C + AssignmentStmt:4( + NameExpr(x) + IntExpr(5)))) + +[case testDoNotStripMethodThatAssignsToAttribute] +# mypy: ignore-errors=True +class C: + def m1(self): + self.x = 0 + def m2(self): + a, self.y = 0 +[out] +MypyFile:1( + ClassDef:2( + C + FuncDef:3( + m1 + Args( + Var(self)) + Block:3( + AssignmentStmt:4( + MemberExpr:4( + NameExpr(self) + x) + IntExpr(0)))) + FuncDef:5( + m2 + Args( + Var(self)) + Block:5( + AssignmentStmt:6( + TupleExpr:6( + NameExpr(a) + MemberExpr:6( + NameExpr(self) + y)) + IntExpr(0)))))) + +[case testDoNotStripMethodThatAssignsToAttributeWithinStatement] +# mypy: ignore-errors=True +class C: + def m1(self): + for x in y: + self.x = 0 + def m2(self): + with x: + self.y = 0 + def m3(self): + if x: + self.y = 0 + else: + x = 4 +[out] +MypyFile:1( + ClassDef:2( + C + FuncDef:3( + m1 + Args( + Var(self)) + Block:3( + ForStmt:4( + NameExpr(x) + NameExpr(y) + Block:4( + AssignmentStmt:5( + MemberExpr:5( + NameExpr(self) + x) + IntExpr(0)))))) + FuncDef:6( + m2 + Args( + Var(self)) + Block:6( + WithStmt:7( + Expr( + NameExpr(x)) + Block:7( + AssignmentStmt:8( + MemberExpr:8( + NameExpr(self) + y) + IntExpr(0)))))) + FuncDef:9( + m3 + Args( + Var(self)) + Block:9( + IfStmt:10( + If( + NameExpr(x)) + Then( + AssignmentStmt:11( + MemberExpr:11( + NameExpr(self) + y) + IntExpr(0))) + Else( + AssignmentStmt:13( + NameExpr(x) + IntExpr(4)))))))) + +[case testDoNotStripMethodThatDefinesAttributeWithoutAssignment] +# mypy: ignore-errors=True +class C: + def m1(self): + with y as self.x: + pass + def m2(self): + for self.y in x: + pass +[out] +MypyFile:1( + ClassDef:2( + C + FuncDef:3( + m1 + Args( + Var(self)) + Block:3( + WithStmt:4( + Expr( + NameExpr(y)) + Target( + MemberExpr:4( + NameExpr(self) + x)) + Block:4( + PassStmt:5())))) + FuncDef:6( + m2 + Args( + Var(self)) + Block:6( + ForStmt:7( + MemberExpr:7( + NameExpr(self) + y) + NameExpr(x) + Block:7( + PassStmt:8())))))) + +[case testStripDecoratedFunctionOrMethod] +# mypy: ignore-errors=True +@deco +def f(): + x = 0 + +class C: + @deco + def m1(self): + x = 0 + + @deco + def m2(self): + self.x = 0 +[out] +MypyFile:1( + Decorator:2( + Var(f) + NameExpr(deco) + FuncDef:3( + f + Block:3())) + ClassDef:6( + C + Decorator:7( + Var(m1) + NameExpr(deco) + FuncDef:8( + m1 + Args( + Var(self)) + Block:8())) + Decorator:11( + Var(m2) + NameExpr(deco) + FuncDef:12( + m2 + Args( + Var(self)) + Block:12( + AssignmentStmt:13( + MemberExpr:13( + NameExpr(self) + x) + IntExpr(0))))))) + +[case testStripOverloadedMethod] +# mypy: ignore-errors=True +class C: + @overload + def m1(self, x: int) -> None: ... + @overload + def m1(self, x: str) -> None: ... + def m1(self, x): + x = 0 + + @overload + def m2(self, x: int) -> None: ... + @overload + def m2(self, x: str) -> None: ... + def m2(self, x): + self.x = 0 +[out] +MypyFile:1( + ClassDef:2( + C + OverloadedFuncDef:3( + Decorator:3( + Var(m1) + NameExpr(overload) + FuncDef:4( + m1 + Args( + Var(self) + Var(x)) + def (self: Any, x: int?) -> None? + Block:4( + ExpressionStmt:4( + Ellipsis)))) + Decorator:5( + Var(m1) + NameExpr(overload) + FuncDef:6( + m1 + Args( + Var(self) + Var(x)) + def (self: Any, x: str?) -> None? + Block:6( + ExpressionStmt:6( + Ellipsis)))) + FuncDef:7( + m1 + Args( + Var(self) + Var(x)) + Block:7())) + OverloadedFuncDef:10( + Decorator:10( + Var(m2) + NameExpr(overload) + FuncDef:11( + m2 + Args( + Var(self) + Var(x)) + def (self: Any, x: int?) -> None? + Block:11( + ExpressionStmt:11( + Ellipsis)))) + Decorator:12( + Var(m2) + NameExpr(overload) + FuncDef:13( + m2 + Args( + Var(self) + Var(x)) + def (self: Any, x: str?) -> None? + Block:13( + ExpressionStmt:13( + Ellipsis)))) + FuncDef:14( + m2 + Args( + Var(self) + Var(x)) + Block:14( + AssignmentStmt:15( + MemberExpr:15( + NameExpr(self) + x) + IntExpr(0))))))) + +[case testStripMethodInNestedClass] +# mypy: ignore-errors=True +class C: + class D: + def m1(self): + self.x = 1 + def m2(self): + return self.x +[out] +MypyFile:1( + ClassDef:2( + C + ClassDef:3( + D + FuncDef:4( + m1 + Args( + Var(self)) + Block:4( + AssignmentStmt:5( + MemberExpr:5( + NameExpr(self) + x) + IntExpr(1)))) + FuncDef:6( + m2 + Args( + Var(self)) + Block:6()))))