Skip to content

Commit 80b3df9

Browse files
committed
Address CR
1 parent 5e89487 commit 80b3df9

3 files changed

Lines changed: 55 additions & 0 deletions

File tree

mypy/build.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,8 @@ def resolve_location(self, graph: dict[str, State], fullname: str) -> Context |
10841084
path = state.manager.maybe_swap_for_shadow_path(state.path)
10851085
source = decode_python_encoding(state.manager.fscache.read(path))
10861086
tree = parse(source, state.path, state.id, state.manager.errors, state.options)
1087+
# TODO: run first pass of semantic analysis on freshly parsed trees,
1088+
# we need this to get correct reachability information.
10871089
self.extra_trees[state.id] = tree
10881090
statements = tree.defs
10891091
while prefix:

mypy/traverser.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,12 @@ def find_definitions(o: Statement, name: str) -> list[Statement]:
10981098

10991099

11001100
class DefinitionSeeker(StatementVisitor[None]):
1101+
"""Find only the topmost functions/classes with the given name.
1102+
1103+
To find a nested class or method, you should split fullname in parts,
1104+
and use this visitor for each part.
1105+
"""
1106+
11011107
def __init__(self, name: str) -> None:
11021108
self.name = name
11031109
self.found: list[Statement] = []
@@ -1150,6 +1156,8 @@ def visit_import_all(self, o: ImportAll, /) -> None:
11501156
pass
11511157

11521158
def visit_block(self, o: Block, /) -> None:
1159+
if o.is_unreachable:
1160+
return
11531161
for s in o.body:
11541162
s.accept(self)
11551163

test-data/unit/check-incremental.test

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7749,3 +7749,48 @@ tmp/b.py:3: note: "lol" defined here
77497749
[out2]
77507750
tmp/a.py:2: error: Unexpected keyword argument "uhhhh" for "lol"
77517751
tmp/b.py:3: note: "lol" defined here
7752+
7753+
[case testCachedUnexpectedKeywordArgumentMethod]
7754+
import a
7755+
[file a.py]
7756+
import b
7757+
b.B().lol(uhhhh=12) # tweak
7758+
[file a.py.2]
7759+
import b
7760+
b.B().lol(uhhhh=12)
7761+
[file b.py]
7762+
class A:
7763+
def lol(self) -> None: pass
7764+
class B:
7765+
def lol(self) -> None: pass
7766+
class C:
7767+
def lol(self) -> None: pass
7768+
[out]
7769+
tmp/a.py:2: error: Unexpected keyword argument "uhhhh" for "lol" of "B"
7770+
tmp/b.py:4: note: "lol" of "B" defined here
7771+
[out2]
7772+
tmp/a.py:2: error: Unexpected keyword argument "uhhhh" for "lol" of "B"
7773+
tmp/b.py:4: note: "lol" of "B" defined here
7774+
7775+
[case testCachedUnexpectedKeywordArgumentMethod2]
7776+
import a
7777+
[file a.py]
7778+
import b
7779+
b.B.BB().lol(uhhhh=12) # tweak
7780+
[file a.py.2]
7781+
import b
7782+
b.B.BB().lol(uhhhh=12)
7783+
[file b.py]
7784+
class A:
7785+
def lol(self) -> None: pass
7786+
class B:
7787+
class BB:
7788+
def lol(self) -> None: pass
7789+
class C:
7790+
def lol(self) -> None: pass
7791+
[out]
7792+
tmp/a.py:2: error: Unexpected keyword argument "uhhhh" for "lol" of "BB"
7793+
tmp/b.py:5: note: "lol" of "BB" defined here
7794+
[out2]
7795+
tmp/a.py:2: error: Unexpected keyword argument "uhhhh" for "lol" of "BB"
7796+
tmp/b.py:5: note: "lol" of "BB" defined here

0 commit comments

Comments
 (0)