-
Notifications
You must be signed in to change notification settings - Fork 260
Open
Labels
needs-discussionAn issue where it's not clear whether there is a bug or we are behaving as expected.An issue where it's not clear whether there is a bug or we are behaving as expected.typecheckingwontfixThis will not be worked onThis will not be worked on
Description
from typing import Any, Literal, Never, overload, reveal_type
@overload
def ndim(shape: tuple[Never, ...]) -> int: ...
@overload
def ndim(shape: tuple[int]) -> Literal[1]: ...
@overload
def ndim(shape: tuple[int, int]) -> Literal[2]: ...
@overload
def ndim(shape: tuple[int, ...]) -> int: ...
def ndim(shape: tuple[int, ...]) -> int:
return len(shape)
def demo_gradual(s: tuple[Any, ...]):
reveal_type(ndim(s)) # Unknown (expected: int)
def demo_one(s: tuple[int]):
reveal_type(ndim(s)) # Literal[1] (OK)
def demo_two(s: tuple[int, int]):
reveal_type(ndim(s)) # Literal[2] (OK)
def demo_variadic(s: tuple[int, ...]):
reveal_type(ndim(s)) # int (OK)In demo_gradual I would have expected it to either
- match the first
tuple[Never, ...]overload, sincetuple[Any, ...](and onlytuple[Any, ...]) is assignable totuple[Never, ...](this matches pyright), or - match all overloads and return the intersection of the results, which would be
intin this case. This would be more in line with the typing spec.
Either way, I expected tuple[Any, ...] to result in an int.
But instead, it returns Unknown, which makes me thing that none of the overloads match.
The other three overloads are behaving correctly.
Metadata
Metadata
Assignees
Labels
needs-discussionAn issue where it's not clear whether there is a bug or we are behaving as expected.An issue where it's not clear whether there is a bug or we are behaving as expected.typecheckingwontfixThis will not be worked onThis will not be worked on