-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Python: __bool__ does not raise TypeError by default #3460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a little more context for why __bool__
is a special case is very helpful. I will gladly admit I didn't know the default behavior of __bool__
, and had to read the FP report to figure out why we needed this change. I have given a suggestion for an explanatory comment, but feel free to formulate it differently 😉
A general approach I find very useful when fixing FPs is to use a 2-step process:
- add FP triggering code to a test-file and update
.expected
results of the qltest - fix the FP in the query and (again) update the
.expected
results of the qltest
In this way it's very easy to see what the FP-alert was, just by reviewing the commits one-by-one (although the .expected
file doesn't change when viewing the diff of all commits). No need to change this PR, but hopefully this can be a useful method to keep in mind for the future 😊
Co-authored-by: Rasmus Wriedt Larsen <rasmuswriedtlarsen@gmail.com>
Thanks, just to make sure I understand: Between step 1 and 2, the |
Ah, Taus has explained this in more detail in my onboarding issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would happen if we now raise a wrong exception for __bool__
? Before, we would get an alert saying we didn't need to implement it at all (which was wrong), but from reading the code, I don't see how the following code would give any alert.
class Foo(object):
def __bool__(self):
raise ZeroDivisionError()
That is a good point, I suppose that should be considered part of solving the problem :-) |
Ah, now I see why the merge was needed. It is because I committed your suggested change. I should've just pulled right after that. |
redo failed |
Check failed due to incorrect line numbers. I must have not run the tests after changing comments or something. |
Also update test expectations with changed line numbers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, very good job 👍
This PR just adds a test to highlight the problem. I will later add a commit to it to also fix the problem.