Commit c35cbd6
authored
Allow redefinitions for function arguments (#20853)
Fixes #19918
Implementation is straightforward, but logic behind is essentially a
compromise. Both empty context and full type context for redefinition
have pros and cons. We select full context first for function arguments
because:
* It avoids false positives in at least some of the "covariant
normalization" patterns. For example `list[str | None]` to `list[str]`
_in a branch_ will infer `list[str | None]` instead of `list[str | None]
| list[str]`. Unconditional normalization like `list[str | None]` to
`list[str]` still doesn't work, but it doesn't work for empty context
either.
* Conceptually function arguments are in between annotated and annotated
variables, in the sense that user doesn't really have an option to leave
them unannotated if they want the redefinition semantics. So we allow
redefinition but use type context behavior like for annotated variables.
cc @JukkaL1 parent 0bf9b14 commit c35cbd6
File tree
5 files changed
+58
-15
lines changed- mypy
- test-data/unit
5 files changed
+58
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | | - | |
| 72 | + | |
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4442 | 4442 | | |
4443 | 4443 | | |
4444 | 4444 | | |
4445 | | - | |
| 4445 | + | |
| 4446 | + | |
| 4447 | + | |
| 4448 | + | |
4446 | 4449 | | |
4447 | 4450 | | |
4448 | 4451 | | |
| |||
4710 | 4713 | | |
4711 | 4714 | | |
4712 | 4715 | | |
4713 | | - | |
4714 | | - | |
| 4716 | + | |
| 4717 | + | |
| 4718 | + | |
| 4719 | + | |
| 4720 | + | |
| 4721 | + | |
| 4722 | + | |
| 4723 | + | |
| 4724 | + | |
4715 | 4725 | | |
4716 | 4726 | | |
4717 | 4727 | | |
| |||
4723 | 4733 | | |
4724 | 4734 | | |
4725 | 4735 | | |
4726 | | - | |
| 4736 | + | |
| 4737 | + | |
4727 | 4738 | | |
4728 | 4739 | | |
4729 | 4740 | | |
| |||
4737 | 4748 | | |
4738 | 4749 | | |
4739 | 4750 | | |
| 4751 | + | |
4740 | 4752 | | |
4741 | 4753 | | |
4742 | 4754 | | |
| |||
4773 | 4785 | | |
4774 | 4786 | | |
4775 | 4787 | | |
4776 | | - | |
4777 | | - | |
| 4788 | + | |
| 4789 | + | |
4778 | 4790 | | |
4779 | 4791 | | |
4780 | 4792 | | |
| |||
4785 | 4797 | | |
4786 | 4798 | | |
4787 | 4799 | | |
4788 | | - | |
| 4800 | + | |
| 4801 | + | |
| 4802 | + | |
4789 | 4803 | | |
4790 | 4804 | | |
4791 | 4805 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1145 | 1145 | | |
1146 | 1146 | | |
1147 | 1147 | | |
| 1148 | + | |
1148 | 1149 | | |
1149 | 1150 | | |
1150 | 1151 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1292 | 1292 | | |
1293 | 1293 | | |
1294 | 1294 | | |
| 1295 | + | |
1295 | 1296 | | |
1296 | 1297 | | |
1297 | 1298 | | |
| |||
1352 | 1353 | | |
1353 | 1354 | | |
1354 | 1355 | | |
| 1356 | + | |
| 1357 | + | |
1355 | 1358 | | |
1356 | 1359 | | |
1357 | 1360 | | |
| |||
1415 | 1418 | | |
1416 | 1419 | | |
1417 | 1420 | | |
1418 | | - | |
1419 | | - | |
1420 | 1421 | | |
1421 | 1422 | | |
1422 | 1423 | | |
| |||
1454 | 1455 | | |
1455 | 1456 | | |
1456 | 1457 | | |
1457 | | - | |
1458 | | - | |
1459 | 1458 | | |
1460 | 1459 | | |
1461 | 1460 | | |
| |||
1475 | 1474 | | |
1476 | 1475 | | |
1477 | 1476 | | |
1478 | | - | |
| 1477 | + | |
1479 | 1478 | | |
1480 | 1479 | | |
1481 | 1480 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
562 | 562 | | |
563 | 563 | | |
564 | 564 | | |
565 | | - | |
566 | | - | |
| 565 | + | |
| 566 | + | |
567 | 567 | | |
568 | 568 | | |
569 | 569 | | |
| |||
1310 | 1310 | | |
1311 | 1311 | | |
1312 | 1312 | | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
0 commit comments