-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
addressed in next versionIssue is fixed and will appear in next published versionIssue is fixed and will appear in next published versionbugSomething isn't workingSomething isn't working
Description
When doing something with a Union, your code should be valid for every choice of the Union:
type U = int | str
def f(u: U) -> None:
u.lower() # type checking errorHaving first-order functions as the Union choices and passing a wrong argument to them also gives an error:
from collections.abc import Callable
type Takes[T] = Callable[[T], object]
type U = Takes[int] | Takes[str]
def f(u: U) -> None:
u(42) # type checking errorBut passing a lambda of a wrong type to a Union of higher-order functions does not produce an error:
from collections.abc import Callable
type Takes[T] = Callable[[T], object]
type U = Takes[Takes[int]] | Takes[Takes[str]]
def f(u: U) -> None:
u(lambda v: v.lower()) # no error :(Mypy shows an error for the above code (substituting PEP 695 type aliases with the old ones, since they're not yet supported by mypy), and I expect pyright to do the same.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
addressed in next versionIssue is fixed and will appear in next published versionIssue is fixed and will appear in next published versionbugSomething isn't workingSomething isn't working