@@ -94,60 +94,89 @@ Assigning an intersection to a non-intersection:
9494
9595``` py
9696from ty_extensions import Intersection
97+ from typing import Protocol
98+
99+ class SupportsFoo (Protocol ):
100+ def foo (self ) -> None : ...
101+
102+ class SupportsBar (Protocol ):
103+ def bar (self ) -> None : ...
104+
105+ class SupportsFooAndBar (Protocol ):
106+ def foo (self ) -> None : ...
107+ def bar (self ) -> None : ...
97108
98- class P : ...
99- class Q : ...
100- class R : ...
109+ class HasFoo :
110+ def foo (self ) -> None : ...
101111
102- def _ (source : Intersection[P, Q]):
103- target: int = source # snapshot
112+ class HasBar :
113+ def bar (self ) -> None : ...
114+
115+ class HasNeither : ...
116+
117+ def _ (source : Intersection[HasBar, HasNeither]):
118+ target: SupportsFooAndBar = source # snapshot
104119```
105120
106121``` snapshot
107- error[invalid-assignment]: Object of type `P & Q` is not assignable to `int`
108- --> src/mdtest_snippet.py:8:13
109- |
110- 8 | target: int = source # snapshot
111- | --- ^^^^^^ Incompatible value of type `P & Q`
112- | |
113- | Declared type
114- |
122+ error[invalid-assignment]: Object of type `HasBar & HasNeither` is not assignable to `SupportsFooAndBar`
123+ --> src/mdtest_snippet.py:23:13
124+ |
125+ 23 | target: SupportsFooAndBar = source # snapshot
126+ | ----------------- ^^^^^^ Incompatible value of type `HasBar & HasNeither`
127+ | |
128+ | Declared type
129+ |
130+ info: no element of intersection `HasBar & HasNeither` is assignable to `SupportsFooAndBar`
131+ info: ├── type `HasBar` is not assignable to protocol `SupportsFooAndBar`
132+ info: │ └── protocol member `foo` is not defined on type `HasBar`
133+ info: └── type `HasNeither` is not assignable to protocol `SupportsFooAndBar`
134+ info: └── protocol member `bar` is not defined on type `HasNeither`
115135```
116136
117137Assigning a non-intersection to an intersection:
118138
119139``` py
120- def _ (source : P ):
121- target: Intersection[P, Q ] = source # snapshot
140+ def _ (source : HasFoo ):
141+ target: Intersection[SupportsFoo, SupportsBar ] = source # snapshot
122142```
123143
124144``` snapshot
125- error[invalid-assignment]: Object of type `P ` is not assignable to `P & Q `
126- --> src/mdtest_snippet.py:10 :13
145+ error[invalid-assignment]: Object of type `HasFoo ` is not assignable to `SupportsFoo & SupportsBar `
146+ --> src/mdtest_snippet.py:25 :13
127147 |
128- 10 | target: Intersection[P, Q ] = source # snapshot
129- | ------------------ ^^^^^^ Incompatible value of type `P `
148+ 25 | target: Intersection[SupportsFoo, SupportsBar ] = source # snapshot
149+ | -------------------------------------- ^^^^^^ Incompatible value of type `HasFoo `
130150 | |
131151 | Declared type
132152 |
153+ info: type `HasFoo` is not assignable to element `SupportsBar` of intersection `SupportsFoo & SupportsBar`
154+ info: └── type `HasFoo` is not assignable to protocol `SupportsBar`
155+ info: └── protocol member `bar` is not defined on type `HasFoo`
133156```
134157
135158Assigning an intersection to an intersection:
136159
137160``` py
138- def _ (source : Intersection[P, R ]):
139- target: Intersection[P, Q ] = source # snapshot
161+ def _ (source : Intersection[HasFoo, HasNeither ]):
162+ target: Intersection[SupportsFoo, SupportsBar ] = source # snapshot
140163```
141164
142165``` snapshot
143- error[invalid-assignment]: Object of type `P & R ` is not assignable to `P & Q `
144- --> src/mdtest_snippet.py:12 :13
166+ error[invalid-assignment]: Object of type `HasFoo & HasNeither ` is not assignable to `SupportsFoo & SupportsBar `
167+ --> src/mdtest_snippet.py:27 :13
145168 |
146- 12 | target: Intersection[P, Q ] = source # snapshot
147- | ------------------ ^^^^^^ Incompatible value of type `P & R `
169+ 27 | target: Intersection[SupportsFoo, SupportsBar ] = source # snapshot
170+ | -------------------------------------- ^^^^^^ Incompatible value of type `HasFoo & HasNeither `
148171 | |
149172 | Declared type
150173 |
174+ info: type `HasFoo & HasNeither` is not assignable to element `SupportsBar` of intersection `SupportsFoo & SupportsBar`
175+ info: └── no element of intersection `HasFoo & HasNeither` is assignable to `SupportsBar`
176+ info: ├── type `HasFoo` is not assignable to protocol `SupportsBar`
177+ info: │ └── protocol member `bar` is not defined on type `HasFoo`
178+ info: └── type `HasNeither` is not assignable to protocol `SupportsBar`
179+ info: └── protocol member `bar` is not defined on type `HasNeither`
151180```
152181
153182## Tuples
@@ -789,6 +818,11 @@ error[invalid-assignment]: Object of type `DoesNotSupportFoo1 & DoesNotSupportFo
789818 | |
790819 | Declared type
791820 |
821+ info: no element of intersection `DoesNotSupportFoo1 & DoesNotSupportFoo2` is assignable to `SupportsFoo`
822+ info: ├── type `DoesNotSupportFoo1` is not assignable to protocol `SupportsFoo`
823+ info: │ └── protocol member `foo` is not defined on type `DoesNotSupportFoo1`
824+ info: └── type `DoesNotSupportFoo2` is not assignable to protocol `SupportsFoo`
825+ info: └── protocol member `foo` is not defined on type `DoesNotSupportFoo2`
792826```
793827
794828## Assigning an overload set
0 commit comments