Skip to content

Commit 6a1aac8

Browse files
committed
Add line number to function cache
1 parent 8f2371a commit 6a1aac8

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

mypy/nodes.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,8 @@ def serialize(self) -> JsonDict:
989989
),
990990
"deprecated": self.deprecated,
991991
"original_first_arg": self.original_first_arg,
992+
"line": self.line,
993+
"column": self.column,
992994
}
993995

994996
@classmethod
@@ -1018,6 +1020,8 @@ def deserialize(cls, data: JsonDict) -> FuncDef:
10181020
else None
10191021
)
10201022
ret.deprecated = data["deprecated"]
1023+
ret.line = data["line"]
1024+
ret.column = data["column"]
10211025
# Leave these uninitialized so that future uses will trigger an error
10221026
del ret.arguments
10231027
del ret.max_pos
@@ -1040,6 +1044,8 @@ def write(self, data: Buffer) -> None:
10401044
self.dataclass_transform_spec.write(data)
10411045
write_str_opt(data, self.deprecated)
10421046
write_str_opt(data, self.original_first_arg)
1047+
write_int(data, self.line)
1048+
write_int(data, self.column)
10431049

10441050
@classmethod
10451051
def read(cls, data: Buffer) -> FuncDef:
@@ -1058,6 +1064,8 @@ def read(cls, data: Buffer) -> FuncDef:
10581064
ret.dataclass_transform_spec = DataclassTransformSpec.read(data)
10591065
ret.deprecated = read_str_opt(data)
10601066
ret.original_first_arg = read_str_opt(data)
1067+
ret.line = read_int(data)
1068+
ret.column = read_int(data)
10611069
# Leave these uninitialized so that future uses will trigger an error
10621070
del ret.arguments
10631071
del ret.max_pos

test-data/unit/check-incremental.test

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ def foo() -> int:
210210
[out2]
211211
tmp/mod2.py:4: error: Incompatible return value type (got "str", expected "int")
212212

213+
-- Function line numbers can affect error messages, so should be part of public interface.
213214
[case testIncrementalInternalScramble]
214215
import mod1
215216

@@ -236,8 +237,8 @@ def bar() -> int:
236237

237238
def baz() -> int:
238239
return 42
239-
[rechecked mod2]
240-
[stale]
240+
[rechecked mod1, mod2]
241+
[stale mod2]
241242

242243
[case testIncrementalMethodInterfaceChange]
243244
import mod1
@@ -6897,3 +6898,20 @@ import does_not_exist
68976898
[builtins fixtures/ops.pyi]
68986899
[out]
68996900
[out2]
6901+
6902+
[case testCachedUnexpectedKeywordArgument]
6903+
import a
6904+
[file a.py]
6905+
import b
6906+
b.lol(uhhhh=12) # tweak
6907+
[file a.py.2]
6908+
import b
6909+
b.lol(uhhhh=12)
6910+
[file b.py]
6911+
def lol() -> None: pass
6912+
[out]
6913+
tmp/a.py:2: error: Unexpected keyword argument "uhhhh" for "lol"
6914+
tmp/b.py:1: note: "lol" defined here
6915+
[out2]
6916+
tmp/a.py:2: error: Unexpected keyword argument "uhhhh" for "lol"
6917+
tmp/b.py:1: note: "lol" defined here

test-data/unit/fine-grained.test

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5178,6 +5178,20 @@ def g(y: T) -> T:
51785178
a.py:2: error: Unexpected keyword argument "x"
51795179
c.py:4: note: Called function defined here
51805180

5181+
[case testFineGrainedUnexpectedKeywordArgument]
5182+
import a
5183+
[file a.py]
5184+
import b
5185+
[file a.py.2]
5186+
import b
5187+
b.lol(uhhhh=12)
5188+
[file b.py]
5189+
def lol() -> None: pass
5190+
[out]
5191+
==
5192+
a.py:2: error: Unexpected keyword argument "uhhhh" for "lol"
5193+
b.py:1: note: "lol" defined here
5194+
51815195
[case testGenericFineCallableInBound]
51825196
import a
51835197
[file a.py]

0 commit comments

Comments
 (0)