You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I promised in python/typing#213 that I'd add support for Intersection, so I'd better do it. I'd like to get Protocol support (#163) in first, though, because most realistic use cases for Intersection involve protocols. Here's a sketch of how the implementation could work:
Add pyanalyze.extensions.Intersection, which would work similar to Union at runtime. Intersection[int, str] means a value which is both an int and a str. We should also support int & str in string annotations, similar to the existing support for int | str.
Add a new IntersectionValue to value.py and handle it in lots of places. For example:
IntersectionValue.can_assign(val) would check that val is assignable to all members of the intersection
val.can_assign(intersectionValue) would succeed if any member of the intersection is assignable to val
Getting an attribute on an IntersectionValue should return something if any member of the intersection has the attribute
What if they have conflicting values? I guess we can return another Intersection
Find ways to use Intersection internally. For example, various narrowing operations could return Intersection objects.
The text was updated successfully, but these errors were encountered:
I promised in python/typing#213 that I'd add support for Intersection, so I'd better do it. I'd like to get Protocol support (#163) in first, though, because most realistic use cases for Intersection involve protocols. Here's a sketch of how the implementation could work:
pyanalyze.extensions.Intersection
, which would work similar toUnion
at runtime.Intersection[int, str]
means a value which is both an int and a str. We should also supportint & str
in string annotations, similar to the existing support forint | str
.IntersectionValue
tovalue.py
and handle it in lots of places. For example:IntersectionValue.can_assign(val)
would check that val is assignable to all members of the intersectionval.can_assign(intersectionValue)
would succeed if any member of the intersection is assignable to valThe text was updated successfully, but these errors were encountered: