Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 11331eb

Browse files
msullivanJukkaL
authored andcommitted
Make expression checking always produce Any once a node has been deferred (#6860)
This fixes an issue where the Any that is inferred temporarily when a node is deferred could cause a bad overload to be picked and produce a spurious error even though it checked properly the *second* time.
1 parent 10ad1af commit 11331eb

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

mypy/checkexpr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3276,7 +3276,7 @@ def accept(self,
32763276
has_any_type(typ)):
32773277
self.msg.disallowed_any_type(typ, node)
32783278

3279-
if not self.chk.in_checked_function():
3279+
if not self.chk.in_checked_function() or self.chk.current_node_deferred:
32803280
return AnyType(TypeOfAny.unannotated)
32813281
else:
32823282
return typ

test-data/unit/check-overloading.test

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5001,3 +5001,31 @@ def f(x):
50015001

50025002
reveal_type(f(g([]))) # E: Revealed type is 'builtins.list[builtins.int]'
50035003
[builtins fixtures/list.pyi]
5004+
5005+
[case testOverloadDeferredNode]
5006+
from typing import Callable, TypeVar, Generic, Any, overload
5007+
5008+
_S = TypeVar('_S')
5009+
_T = TypeVar('_T')
5010+
_R = TypeVar('_R')
5011+
_F = TypeVar('_F', bound=Callable[..., Any])
5012+
5013+
@overload
5014+
def partial(__func: Callable[[_T], _S], __arg: _T) -> Callable[[], _S]: ...
5015+
@overload
5016+
def partial(__func: Callable[[_T, _S], _S], __arg: _T) -> Callable[[_S], _R]: ...
5017+
def partial(*args: Any) -> Any:
5018+
pass
5019+
5020+
5021+
def f(f: Callable[[int], int]) -> None:
5022+
pass
5023+
5024+
def dec(f: Callable[[_S, _T], _R]) -> Callable[[_S, _T], _R]: pass
5025+
5026+
def asdf() -> None:
5027+
f(partial(lol, 0))
5028+
5029+
@dec
5030+
def lol(x: int, y: int) -> int:
5031+
pass

0 commit comments

Comments
 (0)