-
Notifications
You must be signed in to change notification settings - Fork 19
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
[Adjust Rule] SIM106: Error cases first only if it's not "NotImplementedError" #14
Comments
My take on this is that it should be allowed to raise an exception in an if path.is_dir():
...
elif path.is_file():
...
else:
raise ValueError('File or directory expected') Fail-fast in this case would be to do if not (path.is_file() or path.is_dir()):
raise ValueError('File or directory expected')
if path.is_file():
...
elif path.is_dir():
... which makes it more complicated, IMO. In case there's no if path.is_file():
...
else:
raise NotImplementedError IMHO it's clearer to just do if not path.is_file():
raise NotImplementedError
# We're sure it's a file
... 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: if path.is_file():
...
return something
raise NotImplementedError That's also not detected at the moment, but detecting such things might be a bit more complicated. |
Hey, good points! Thank you for taking the time and sharing this. At the moment, I'm too busy with other stuff. I don't think I can work in this in the next 2 weeks. But I will do it in November :-) |
The final note is actually also fine, I think. I personally can read the "else" version better, but I can understand if people want the I've just had a look at this issue. I've created a test, but it's not easy to directly solve it. Essentially, the |
This issue is blocked by #21 |
Since the blocking issue is resolved, is there any progress here? :) |
Desired change
Explanation
Throwing an exception for potentially forgotten implementation is better than potentially returning None or making the last one catch all.
Example
The text was updated successfully, but these errors were encountered: