Commit 03fe560
[ty] Substitute for
This patch updates our protocol assignability checks to substitute for
any occurrences of `typing.Self` in method signatures, replacing it with
the class being checked for assignability against the protocol.
This requires a new helper method on signatures, `apply_self`, which
substitutes occurrences of `typing.Self` _without_ binding the `self`
parameter.
We also update the `try_upcast_to_callable` method. Before, it would
return a `Type`, since certain types upcast to a _union_ of callables,
not to a single callable. However, even in that case, we know that every
element of the union is a callable. We now return a vector of
`CallableType`. (Actually a smallvec to handle the most common case of a
single callable; and wrapped in a new type so that we can provide helper
methods.) If there is more than one element in the result, it represents
a union of callables. This lets callers get at the `CallableType`
instances in a more type-safe way. (This makes it easier for our
protocol checking code to call the new `apply_self` helper.) We also
provide an `into_type` method so that callers that really do want a
`Type` can get the original result easily.
---------
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>typing.Self when checking protocol members (#21569)1 parent 68343e7 commit 03fe560
File tree
13 files changed
+317
-128
lines changed- crates/ty_python_semantic
- resources/mdtest
- src
- semantic_index
- types
- infer
- builder
- property_tests
13 files changed
+317
-128
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2003 | 2003 | | |
2004 | 2004 | | |
2005 | 2005 | | |
| 2006 | + | |
2006 | 2007 | | |
2007 | 2008 | | |
2008 | 2009 | | |
| |||
2094 | 2095 | | |
2095 | 2096 | | |
2096 | 2097 | | |
| 2098 | + | |
| 2099 | + | |
| 2100 | + | |
| 2101 | + | |
| 2102 | + | |
| 2103 | + | |
| 2104 | + | |
2097 | 2105 | | |
2098 | 2106 | | |
2099 | 2107 | | |
| |||
2112 | 2120 | | |
2113 | 2121 | | |
2114 | 2122 | | |
2115 | | - | |
2116 | | - | |
| 2123 | + | |
2117 | 2124 | | |
2118 | 2125 | | |
2119 | 2126 | | |
| |||
2126 | 2133 | | |
2127 | 2134 | | |
2128 | 2135 | | |
| 2136 | + | |
| 2137 | + | |
2129 | 2138 | | |
2130 | 2139 | | |
2131 | 2140 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1376 | 1376 | | |
1377 | 1377 | | |
1378 | 1378 | | |
1379 | | - | |
1380 | | - | |
1381 | | - | |
| 1379 | + | |
1382 | 1380 | | |
1383 | 1381 | | |
1384 | 1382 | | |
| |||
1461 | 1459 | | |
1462 | 1460 | | |
1463 | 1461 | | |
1464 | | - | |
| 1462 | + | |
1465 | 1463 | | |
1466 | 1464 | | |
1467 | 1465 | | |
| |||
Lines changed: 9 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
208 | 208 | | |
209 | 209 | | |
210 | 210 | | |
211 | | - | |
| 211 | + | |
212 | 212 | | |
213 | 213 | | |
214 | 214 | | |
| |||
871 | 871 | | |
872 | 872 | | |
873 | 873 | | |
874 | | - | |
875 | | - | |
876 | | - | |
877 | | - | |
878 | | - | |
879 | | - | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
880 | 882 | | |
881 | 883 | | |
882 | 884 | | |
| |||
0 commit comments