Override __int__ and __index__ for bool in builtins.pyi - #16067
Override __int__ and __index__ for bool in builtins.pyi#16067jonathandung wants to merge 1 commit into
__int__ and __index__ for bool in builtins.pyi#16067Conversation
This comment has been minimized.
This comment has been minimized.
|
I do not understand the mypy failure involving the term "erased type". |
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
|
This is a mypy bug, see python/mypy#14764. You may try to ignore this error using |
|
To be clear, I don't think this, on its own, would help ty much with regards to the linked issue. I don't believe we currently look at these dunders when implementing our special casing for arithmetic regarding literal integers or bools. I'm also not sure we'd want to start looking at these dunders if we were to implement the feature request in the linked issue: I think there are probably simpler ways of achieving that goal. This PR might be worth doing anyway, though; I don't have a position on that |
Such that the fact that they only return
1forTrueand0forFalsemay be represented without violating the Liskov Substitution Principle. This change is motivated by astral-sh/ty#4048, from which I learnt no type checker supports the inference of the value of booleans in integer operation context, but that may be fixable by a stub-side modification.