[Adjust Rule] SIM106: Error cases first only if it's not "NotImplementedError"
See original GitHub issueDesired change
- Rule(s): SIM106
- Adjustment: Make an exception for the NotImplementedError
Explanation
Throwing an exception for potentially forgotten implementation is better than potentially returning None or making the last one catch all.
Example
if merge_method in ["take_right_shallow", "take_right_deep"]:
...
elif merge_method == "take_left_shallow":
...
elif merge_method == "take_left_deep":
...
elif merge_method == "sum":
...
else:
raise NotImplementedError
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
python - Why return NotImplemented instead of raising ...
When Python interpreter checks whether a.__eq__(b) returned NotImplemented, couldn't it just as easily catch NotImplementedError instead (and ...
Read more >raise NotImplemented should be raise NotImplementedError ...
Raise NotImplementedError to indicate that a super-class method is not implemented and that child classes should implement it.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Since the blocking issue is resolved, is there any progress here? 😃
My take on this is that it should be allowed to raise an exception in an
elseblock when there’s a chain ofifs, regardless of the type of exception raised. Take for instance:Fail-fast in this case would be to do
which makes it more complicated, IMO.
In case there’s no
elifs, e.g.IMHO it’s clearer to just do
although the former would be allowed by the proposed adjustment.
A final note (perhaps a bit outside the scope of this issue) is the following:
That’s also not detected at the moment, but detecting such things might be a bit more complicated.