Commit c36cf36
Skip inapplicable parent overloads during override checking (#2880)
Summary:
When binding an overloaded method to an object, filter out overloads whose
`self` parameter type is incompatible with the object type. This fixes false
positive `bad-override` errors when subclassing `str` (and similar classes
with `LiteralString` overloads) and adding optional parameters to overridden
methods.
For example, `str.upper()` has two overloads:
1. `(self: LiteralString) -> LiteralString`
2. `(self) -> str`
When `MyString(str)` overrides `upper()`, the override check previously
required the child to satisfy ALL parent overloads, including the
`LiteralString` one. Since `MyString` is not `LiteralString`, the check
failed with a false positive. Now, inapplicable overloads are filtered out
during method binding.
Fixes #2309
Differential Revision: D978051781 parent e4e54a9 commit c36cf36
2 files changed
+68
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3165 | 3165 | | |
3166 | 3166 | | |
3167 | 3167 | | |
| 3168 | + | |
3168 | 3169 | | |
3169 | 3170 | | |
3170 | 3171 | | |
| |||
4239 | 4240 | | |
4240 | 4241 | | |
4241 | 4242 | | |
| 4243 | + | |
| 4244 | + | |
| 4245 | + | |
| 4246 | + | |
| 4247 | + | |
| 4248 | + | |
| 4249 | + | |
| 4250 | + | |
| 4251 | + | |
| 4252 | + | |
| 4253 | + | |
| 4254 | + | |
| 4255 | + | |
| 4256 | + | |
| 4257 | + | |
| 4258 | + | |
| 4259 | + | |
| 4260 | + | |
| 4261 | + | |
| 4262 | + | |
| 4263 | + | |
| 4264 | + | |
| 4265 | + | |
| 4266 | + | |
| 4267 | + | |
| 4268 | + | |
| 4269 | + | |
| 4270 | + | |
| 4271 | + | |
| 4272 | + | |
| 4273 | + | |
| 4274 | + | |
| 4275 | + | |
| 4276 | + | |
| 4277 | + | |
| 4278 | + | |
| 4279 | + | |
| 4280 | + | |
| 4281 | + | |
| 4282 | + | |
| 4283 | + | |
| 4284 | + | |
| 4285 | + | |
| 4286 | + | |
| 4287 | + | |
| 4288 | + | |
| 4289 | + | |
| 4290 | + | |
| 4291 | + | |
| 4292 | + | |
| 4293 | + | |
| 4294 | + | |
| 4295 | + | |
| 4296 | + | |
| 4297 | + | |
| 4298 | + | |
| 4299 | + | |
| 4300 | + | |
| 4301 | + | |
| 4302 | + | |
| 4303 | + | |
| 4304 | + | |
| 4305 | + | |
| 4306 | + | |
| 4307 | + | |
| 4308 | + | |
4242 | 4309 | | |
4243 | 4310 | | |
4244 | 4311 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1298 | 1298 | | |
1299 | 1299 | | |
1300 | 1300 | | |
1301 | | - | |
1302 | 1301 | | |
1303 | 1302 | | |
1304 | 1303 | | |
1305 | | - | |
| 1304 | + | |
1306 | 1305 | | |
1307 | 1306 | | |
1308 | 1307 | | |
0 commit comments