Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly process nested definitions in astmerge #14104

Merged
merged 3 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mypy/server/astmerge.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ def visit_mypy_file(self, node: MypyFile) -> None:
super().visit_mypy_file(node)

def visit_block(self, node: Block) -> None:
super().visit_block(node)
node.body = self.replace_statements(node.body)
super().visit_block(node)

def visit_func_def(self, node: FuncDef) -> None:
node = self.fixup(node)
Expand Down
50 changes: 50 additions & 0 deletions test-data/unit/fine-grained.test
Original file line number Diff line number Diff line change
Expand Up @@ -10130,3 +10130,53 @@ b.py:2: error: "int" not callable
a.py:1: error: Unsupported operand types for + ("int" and "str")
1 + ''
^~

[case testNoNestedDefinitionCrash]
import m
[file m.py]
from typing import Any, TYPE_CHECKING

class C:
if TYPE_CHECKING:
def __init__(self, **kw: Any): ...

C
[file m.py.2]
from typing import Any, TYPE_CHECKING

class C:
if TYPE_CHECKING:
def __init__(self, **kw: Any): ...

C
# change
[builtins fixtures/dict.pyi]
[out]
==

[case testNoNestedDefinitionCrash2]
import m
[file m.py]
from typing import Any

class C:
try:
def __init__(self, **kw: Any): ...
except:
pass

C
[file m.py.2]
from typing import Any

class C:
try:
def __init__(self, **kw: Any): ...
except:
pass

C
# change
[builtins fixtures/dict.pyi]
[out]
==