-
Notifications
You must be signed in to change notification settings - Fork 276
Intersection between Protocol and almost overlapping class is simplified incorrectly #770
Copy link
Copy link
Open
Labels
ProtocolsbugSomething isn't workingSomething isn't workingset-theoretic typesunions, intersections and moreunions, intersections and more
Milestone
Description
Summary
In the below example, ty incorrectly simplifies a Protocol out of an intersection when it almost (but not quite) is the same as a nominal class.
https://play.ty.dev/9b0ac32c-9200-4558-8269-6e3f3bea1837
from typing import Protocol
from ty_extensions import Intersection, Not
class Proto(Protocol):
def meth(self) -> int: ...
class X:
def meth(self) -> int | str: return 42
def f(x: Intersection[X, Proto]):
reveal_type(x) # X (expect X & Proto)
reveal_type(x.meth()) # int | str (expect int)This can also lead to incorrect type inference without explicit Intersection types (https://play.ty.dev/6185eec9-9e29-49f6-b0ef-b817844fedb5):
from typing import Protocol
class Proto(Protocol):
def meth(self) -> int: ...
class X:
def meth(self) -> int | str: return 42
def f(x: Proto):
if isinstance(x, X):
reveal_type(x) # X
reveal_type(x.meth()) # int | strVersion
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
ProtocolsbugSomething isn't workingSomething isn't workingset-theoretic typesunions, intersections and moreunions, intersections and more