Commit 7141d6b
authored
More principled approach for callable vs callable inference (python#15910)
Fixes python#702 (one of the oldest open
issues)
The approach is quite simple, I essentially replicate the logic from
subtyping check, while replacing each `is_subtype()` call with
`infer_constraints()` call. Note that we don't have various options
available in `constraints.py` so I use all checks, even those that may
be skipped with some strictness flags (so we can infer as many
constraints as possible). Depending on the output of `mypy_primer` we
can try to tune this.
Note that while I was looking at subtyping code, I noticed couple
inconsistencies for ParamSpecs, I added TODOs for them (and updated some
existing TODOs). I also deleted some code that should be dead code after
my previous cleanup.
Among inconsistencies most notably, subtyping between `Parameters` uses
wrong (opposite) direction. Normally, `Parameters` entity behaves
covariantly (w.r.t. types of individual arguments) as a single big
argument, like a tuple plus a map. But then this entity appears in a
contravariant position in `Callable`. This is how we handle it in
`constraints.py`, `join.py`, `meet.py` etc. I tried to fix the
left/right order in `visit_parameters()`, but then one test failed (and
btw same test would also fail if I would try to fix variance in
`visit_instance()`). I decided to leave this for separate PR(s).1 parent e804e8d commit 7141d6b
File tree
5 files changed
+260
-55
lines changed- mypy
- test-data/unit
5 files changed
+260
-55
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
595 | 595 | | |
596 | 596 | | |
597 | 597 | | |
598 | | - | |
599 | | - | |
600 | | - | |
601 | | - | |
602 | | - | |
603 | | - | |
604 | | - | |
605 | | - | |
606 | | - | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
607 | 603 | | |
608 | 604 | | |
609 | 605 | | |
| |||
722 | 718 | | |
723 | 719 | | |
724 | 720 | | |
725 | | - | |
| 721 | + | |
| 722 | + | |
726 | 723 | | |
727 | 724 | | |
728 | 725 | | |
| |||
793 | 790 | | |
794 | 791 | | |
795 | 792 | | |
796 | | - | |
| 793 | + | |
| 794 | + | |
797 | 795 | | |
798 | 796 | | |
799 | 797 | | |
| |||
962 | 960 | | |
963 | 961 | | |
964 | 962 | | |
965 | | - | |
966 | | - | |
967 | 963 | | |
968 | 964 | | |
969 | | - | |
970 | | - | |
971 | | - | |
972 | | - | |
973 | | - | |
974 | | - | |
975 | | - | |
976 | | - | |
977 | | - | |
978 | | - | |
979 | | - | |
980 | | - | |
981 | 965 | | |
982 | | - | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
983 | 969 | | |
984 | 970 | | |
985 | 971 | | |
| |||
1028 | 1014 | | |
1029 | 1015 | | |
1030 | 1016 | | |
1031 | | - | |
1032 | | - | |
1033 | | - | |
1034 | | - | |
1035 | | - | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
1036 | 1020 | | |
1037 | 1021 | | |
1038 | 1022 | | |
| |||
1435 | 1419 | | |
1436 | 1420 | | |
1437 | 1421 | | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + | |
| 1439 | + | |
| 1440 | + | |
| 1441 | + | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
| 1453 | + | |
| 1454 | + | |
| 1455 | + | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + | |
| 1459 | + | |
| 1460 | + | |
| 1461 | + | |
| 1462 | + | |
| 1463 | + | |
| 1464 | + | |
| 1465 | + | |
| 1466 | + | |
| 1467 | + | |
| 1468 | + | |
| 1469 | + | |
| 1470 | + | |
| 1471 | + | |
| 1472 | + | |
| 1473 | + | |
| 1474 | + | |
| 1475 | + | |
| 1476 | + | |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
| 1481 | + | |
| 1482 | + | |
| 1483 | + | |
| 1484 | + | |
| 1485 | + | |
| 1486 | + | |
| 1487 | + | |
| 1488 | + | |
| 1489 | + | |
| 1490 | + | |
| 1491 | + | |
| 1492 | + | |
| 1493 | + | |
| 1494 | + | |
| 1495 | + | |
| 1496 | + | |
| 1497 | + | |
| 1498 | + | |
| 1499 | + | |
| 1500 | + | |
| 1501 | + | |
| 1502 | + | |
| 1503 | + | |
| 1504 | + | |
| 1505 | + | |
| 1506 | + | |
| 1507 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
590 | 590 | | |
591 | 591 | | |
592 | 592 | | |
| 593 | + | |
593 | 594 | | |
594 | 595 | | |
595 | 596 | | |
| |||
666 | 667 | | |
667 | 668 | | |
668 | 669 | | |
669 | | - | |
670 | | - | |
671 | | - | |
672 | | - | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
673 | 673 | | |
674 | 674 | | |
675 | | - | |
| 675 | + | |
676 | 676 | | |
677 | 677 | | |
678 | 678 | | |
| |||
723 | 723 | | |
724 | 724 | | |
725 | 725 | | |
726 | | - | |
727 | | - | |
728 | | - | |
729 | | - | |
730 | | - | |
731 | | - | |
732 | | - | |
733 | | - | |
734 | 726 | | |
735 | 727 | | |
736 | 728 | | |
| |||
1456 | 1448 | | |
1457 | 1449 | | |
1458 | 1450 | | |
1459 | | - | |
1460 | 1451 | | |
1461 | 1452 | | |
1462 | 1453 | | |
| |||
1480 | 1471 | | |
1481 | 1472 | | |
1482 | 1473 | | |
1483 | | - | |
1484 | 1474 | | |
1485 | 1475 | | |
1486 | 1476 | | |
| |||
1534 | 1524 | | |
1535 | 1525 | | |
1536 | 1526 | | |
1537 | | - | |
| 1527 | + | |
1538 | 1528 | | |
1539 | 1529 | | |
1540 | 1530 | | |
| |||
1548 | 1538 | | |
1549 | 1539 | | |
1550 | 1540 | | |
1551 | | - | |
| 1541 | + | |
1552 | 1542 | | |
1553 | 1543 | | |
1554 | 1544 | | |
| |||
1575 | 1565 | | |
1576 | 1566 | | |
1577 | 1567 | | |
1578 | | - | |
| 1568 | + | |
1579 | 1569 | | |
1580 | 1570 | | |
1581 | 1571 | | |
| |||
1643 | 1633 | | |
1644 | 1634 | | |
1645 | 1635 | | |
| 1636 | + | |
| 1637 | + | |
| 1638 | + | |
| 1639 | + | |
1646 | 1640 | | |
1647 | 1641 | | |
1648 | 1642 | | |
| |||
1670 | 1664 | | |
1671 | 1665 | | |
1672 | 1666 | | |
1673 | | - | |
| 1667 | + | |
1674 | 1668 | | |
1675 | 1669 | | |
1676 | 1670 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1545 | 1545 | | |
1546 | 1546 | | |
1547 | 1547 | | |
1548 | | - | |
1549 | | - | |
1550 | | - | |
1551 | 1548 | | |
1552 | 1549 | | |
1553 | 1550 | | |
| |||
1559 | 1556 | | |
1560 | 1557 | | |
1561 | 1558 | | |
| 1559 | + | |
| 1560 | + | |
1562 | 1561 | | |
1563 | 1562 | | |
1564 | 1563 | | |
| |||
1602 | 1601 | | |
1603 | 1602 | | |
1604 | 1603 | | |
1605 | | - | |
| 1604 | + | |
1606 | 1605 | | |
1607 | 1606 | | |
1608 | 1607 | | |
| |||
2046 | 2045 | | |
2047 | 2046 | | |
2048 | 2047 | | |
2049 | | - | |
2050 | 2048 | | |
2051 | 2049 | | |
2052 | 2050 | | |
| |||
0 commit comments