Repository navigation
Commit aada81c
Let
Summary:
`functools.total_ordering` only fills in ordering methods that a class doesn't already have, whether they're defined directly or inherited. Pyrefly decided what was missing using a lookup that skips every synthesized member in the MRO, so it couldn't see ordering methods generated on an ancestor dataclass. For a subclass of `dataclass(order=True)`, that caused two problems:
- `total_ordering class B(D): pass` reported a false "must define at least one of the rich comparison methods" error.
- With a hand-written `__lt__`, pyrefly made up `__gt__`/`__le__`/`__ge__` on the subclass from it. At runtime the subclass keeps `D`'s methods.
The same blind spot applied to methods that `total_ordering` filled in on an ancestor. The lookup only needs to skip members synthesized on the class itself, because those are what's being computed. Members synthesized on ancestors are already settled, so a new lookup ignores only the class's own synthesized fields, and `total_ordering` uses it.
___
landed-with-radar-review
Differential Revision: D126992833
fbshipit-source-id: ccc366ab1e9c0399165e02fe3ed6996eacf33324total_ordering see comparison methods generated on ancestors1 parent 5d6ea02 commit aada81c
3 files changed
Lines changed: 68 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4944 | 4944 | | |
4945 | 4945 | | |
4946 | 4946 | | |
| 4947 | + | |
| 4948 | + | |
| 4949 | + | |
| 4950 | + | |
| 4951 | + | |
| 4952 | + | |
| 4953 | + | |
| 4954 | + | |
| 4955 | + | |
| 4956 | + | |
| 4957 | + | |
| 4958 | + | |
| 4959 | + | |
| 4960 | + | |
| 4961 | + | |
| 4962 | + | |
| 4963 | + | |
4947 | 4964 | | |
4948 | 4965 | | |
4949 | 4966 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
| 64 | + | |
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
| 82 | + | |
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
567 | 567 | | |
568 | 568 | | |
569 | 569 | | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
570 | 618 | | |
571 | 619 | | |
572 | 620 | | |
| |||
0 commit comments