Commit fa01a07
authored
Fix incorrect truthyness for Enum types and literals (#17337)
Fixes: #17333
This ensures `can_be_true` and `can_be_false` on enum literals depends
on the specific `Enum` fallback type behind the `Literal`, since
`__bool__` can be overriden like on any other type.
Additionally typeops `true_only` and `false_only` now respect the
metaclass when looking up the return values of `__bool__` and `__len__`,
which ensures that a default `Enum` that doesn't override `__bool__` is
still considered always truthy.1 parent 3e52d0c commit fa01a07
File tree
15 files changed
+136
-4
lines changed- mypy
- test-data/unit
- fixtures
- lib-stub
15 files changed
+136
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
650 | 650 | | |
651 | 651 | | |
652 | 652 | | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
653 | 658 | | |
654 | 659 | | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
655 | 663 | | |
656 | 664 | | |
657 | 665 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2818 | 2818 | | |
2819 | 2819 | | |
2820 | 2820 | | |
| 2821 | + | |
| 2822 | + | |
| 2823 | + | |
| 2824 | + | |
| 2825 | + | |
| 2826 | + | |
| 2827 | + | |
| 2828 | + | |
| 2829 | + | |
| 2830 | + | |
| 2831 | + | |
| 2832 | + | |
| 2833 | + | |
| 2834 | + | |
2821 | 2835 | | |
| 2836 | + | |
| 2837 | + | |
2822 | 2838 | | |
2823 | 2839 | | |
2824 | 2840 | | |
| 2841 | + | |
| 2842 | + | |
2825 | 2843 | | |
2826 | 2844 | | |
2827 | 2845 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
967 | 967 | | |
968 | 968 | | |
969 | 969 | | |
| 970 | + | |
970 | 971 | | |
971 | 972 | | |
972 | 973 | | |
| |||
0 commit comments