Commit 1eb9d4c
authored
Support properties with setter type different from getter type (#18510)
Fixes #3004
Fixes #11892
Fixes #12892
Fixes #14301
_Note:_ this PR should be reviewed with "hide whitespace" option (in
couple long functions I replace huge `if x: ...` with `if not x: return;
...` to reduce indent level).
The core logic is quite straightforward (almost trivial). The only
couple things are:
* We should be careful with binder (we simpy can't use it for properties
with setter type different from getter type, since we don't know
underlying property implementation)
* We need to handle gracefully existing settable properties that are
generated by plugins
The tricky part is subclassing and protocols. The summary is as
following:
* For protocols I simply implement everything the "correct way", i.e.
for settable attributes (whether it is a variable or a settable
property) compare getter types covariantly and setter types
contravariantly. The tricky part here is generating meaningful error
messages that are also not too verbose.
* For subclassing I cannot simply do the same, because there is a flag
about covariant mutable override, that is off by default. So instead
what I do is if either subclass node, or superclass node is a "custom
property" (i.e. a property with setter type different from getter type),
then I use the "correct way", otherwise the old logic (i.e. flag
dependent check) is used.
Two things that are not implemented are multiple inheritance, and new
generic syntax (inferred variance). In these cases setter types are
simply ignored. There is nothing conceptually difficult about these, I
simply run out of steam (and the PR is getting big). I left `TODO`s in
code for these. In most cases these will generate false negatives (and
they are already kind of corner cases) so I think it is OK to postpone
these indefinitely.1 parent 3ced11a commit 1eb9d4c
File tree
15 files changed
+1077
-233
lines changed- mypy
- server
- test-data/unit
- fixtures
15 files changed
+1077
-233
lines changedLarge diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
658 | 658 | | |
659 | 659 | | |
660 | 660 | | |
661 | | - | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
662 | 665 | | |
663 | 666 | | |
664 | 667 | | |
| |||
776 | 779 | | |
777 | 780 | | |
778 | 781 | | |
779 | | - | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
780 | 789 | | |
781 | 790 | | |
782 | 791 | | |
| |||
834 | 843 | | |
835 | 844 | | |
836 | 845 | | |
837 | | - | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
838 | 850 | | |
839 | 851 | | |
840 | 852 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| |||
172 | 172 | | |
173 | 173 | | |
174 | 174 | | |
| 175 | + | |
175 | 176 | | |
176 | 177 | | |
177 | 178 | | |
178 | 179 | | |
| 180 | + | |
179 | 181 | | |
180 | 182 | | |
181 | 183 | | |
| |||
196 | 198 | | |
197 | 199 | | |
198 | 200 | | |
199 | | - | |
| 201 | + | |
| 202 | + | |
200 | 203 | | |
201 | 204 | | |
202 | 205 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
210 | 210 | | |
211 | 211 | | |
212 | 212 | | |
| 213 | + | |
| 214 | + | |
213 | 215 | | |
214 | 216 | | |
215 | 217 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| 59 | + | |
59 | 60 | | |
60 | 61 | | |
61 | 62 | | |
| |||
186 | 187 | | |
187 | 188 | | |
188 | 189 | | |
| 190 | + | |
189 | 191 | | |
190 | 192 | | |
191 | | - | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
192 | 197 | | |
193 | 198 | | |
194 | 199 | | |
| |||
1164 | 1169 | | |
1165 | 1170 | | |
1166 | 1171 | | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
1167 | 1186 | | |
1168 | 1187 | | |
1169 | 1188 | | |
| |||
2201 | 2220 | | |
2202 | 2221 | | |
2203 | 2222 | | |
2204 | | - | |
| 2223 | + | |
2205 | 2224 | | |
2206 | 2225 | | |
| 2226 | + | |
2207 | 2227 | | |
2208 | 2228 | | |
2209 | 2229 | | |
2210 | 2230 | | |
2211 | | - | |
2212 | | - | |
| 2231 | + | |
| 2232 | + | |
| 2233 | + | |
| 2234 | + | |
2213 | 2235 | | |
2214 | 2236 | | |
2215 | 2237 | | |
2216 | 2238 | | |
2217 | 2239 | | |
| 2240 | + | |
| 2241 | + | |
| 2242 | + | |
| 2243 | + | |
| 2244 | + | |
| 2245 | + | |
| 2246 | + | |
2218 | 2247 | | |
2219 | | - | |
| 2248 | + | |
| 2249 | + | |
| 2250 | + | |
2220 | 2251 | | |
2221 | 2252 | | |
2222 | 2253 | | |
| |||
3029 | 3060 | | |
3030 | 3061 | | |
3031 | 3062 | | |
3032 | | - | |
| 3063 | + | |
3033 | 3064 | | |
3034 | | - | |
| 3065 | + | |
3035 | 3066 | | |
3036 | 3067 | | |
3037 | | - | |
| 3068 | + | |
3038 | 3069 | | |
3039 | 3070 | | |
3040 | 3071 | | |
| |||
3044 | 3075 | | |
3045 | 3076 | | |
3046 | 3077 | | |
3047 | | - | |
3048 | | - | |
3049 | 3078 | | |
3050 | | - | |
| 3079 | + | |
| 3080 | + | |
| 3081 | + | |
| 3082 | + | |
| 3083 | + | |
| 3084 | + | |
| 3085 | + | |
| 3086 | + | |
| 3087 | + | |
| 3088 | + | |
| 3089 | + | |
| 3090 | + | |
| 3091 | + | |
| 3092 | + | |
| 3093 | + | |
| 3094 | + | |
| 3095 | + | |
| 3096 | + | |
| 3097 | + | |
| 3098 | + | |
| 3099 | + | |
| 3100 | + | |
3051 | 3101 | | |
3052 | 3102 | | |
3053 | 3103 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
977 | 977 | | |
978 | 978 | | |
979 | 979 | | |
| 980 | + | |
980 | 981 | | |
981 | 982 | | |
982 | 983 | | |
| |||
1011 | 1012 | | |
1012 | 1013 | | |
1013 | 1014 | | |
| 1015 | + | |
| 1016 | + | |
1014 | 1017 | | |
1015 | 1018 | | |
1016 | 1019 | | |
| |||
1076 | 1079 | | |
1077 | 1080 | | |
1078 | 1081 | | |
| 1082 | + | |
1079 | 1083 | | |
1080 | 1084 | | |
1081 | 1085 | | |
| |||
1087 | 1091 | | |
1088 | 1092 | | |
1089 | 1093 | | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
1090 | 1099 | | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
1091 | 1106 | | |
1092 | 1107 | | |
1093 | 1108 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
248 | 253 | | |
249 | 254 | | |
250 | 255 | | |
| |||
258 | 263 | | |
259 | 264 | | |
260 | 265 | | |
| 266 | + | |
261 | 267 | | |
262 | 268 | | |
263 | 269 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
330 | 330 | | |
331 | 331 | | |
332 | 332 | | |
| 333 | + | |
333 | 334 | | |
334 | 335 | | |
335 | 336 | | |
| |||
0 commit comments