You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In that discussion, Eric Traut, author of pyright wrote:
I think there's a good argument to be made that conditionals in Python don't use the result of bool in a covariant manner. They require a bool response and generate an exception if bool returns any other type. In other words, they treat the result as invariant, not covariant. That would imply that if bool is annotated with a return type of anything other than bool, it should be treated as an error when used in a conditional.
He has changed pyright to recognize this. He asked that it also be discussed here to see if other type checkers should do the same.
Note - this pattern is used in pandas as the result of testing the truth of a pandas DataFrame or Series is ambiguous, so pandas raises an Exception
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Consider the following code that raises an exception:
In this case, we would like the type checker to report that
if y
is invalid, because__bool__()
returnsNoReturn
This came up here: microsoft/pyright#5039
In that discussion, Eric Traut, author of
pyright
wrote:He has changed
pyright
to recognize this. He asked that it also be discussed here to see if other type checkers should do the same.Note - this pattern is used in
pandas
as the result of testing the truth of a pandasDataFrame
orSeries
is ambiguous, so pandas raises anException
Beta Was this translation helpful? Give feedback.
All reactions