-
Notifications
You must be signed in to change notification settings - Fork 78
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
Existing linters, type-checker configuration or other tooling to identify unused Results? #45
Comments
Good questions. I don't have any good answers for you (unfortunately I don't use Python day-to-day). But we can leave this open to see if anyone else has any good ideas. The only comparison I can think of to what I believe you're experiencing is with TypeScript. Which provides strict null checks and non-strict null checks -- ie Does the sound accurate to what you're seeing? Does mypy or pyright offter strict checks like that? Quick search shows me this bit which seems related,
|
Thanks for the response. The particular case I'm worried about is: def go_do_something_which_might_error() -> Result[None, str]:
return Err("ahhhh")
if __name__ == "__main__":
go_do_something_which_might_error()
do_something_assuming_the_above_succeeded() In the above, In Rust, What I'm hoping for is suggestions on Python tooling that might detect this case. |
Relevant mypy issue (funny enough it reference right back to this very library :) ) From TypeScript experience, I know this is definitely possible with typecheckers/linters...whether the Python ecosystem has something in place, I don't know. |
Wait, found something promising,
from https://github.com/microsoft/pyright/blob/main/docs/configuration.md |
That's exactly what I was looking for; evidently, my Ctrl+F attempt was very poorly executed! I saw the mypy thread but missed the reference to Pyright, and I guess didn't use the right terms in their actual docs. It works great. Thank you! |
We'd welcome your feedback and experience if you end up playing around with that. Let us know so we can possibly update the README here for overall better user experience with this library. |
Just to document this somewhere, I think I've came across the very same issue as the TS reported. It would be super nice if this question / feature request was kept in a roadmap of some sort, so that if this gets implemented in |
I'm rather fond of the promise of this library in my type-annotated codebase. I already type-check it with Pyright. However, it seems easy to accidentally miss a returned
Result
if the method otherwise returnsNone
. i.e., if I care about the value in case of success, I'll surely get a type error in the case that I fail to check for error variants; if I don't, then I might not be warned about theResult
being there at all.This seems like it would be a common problem for projects using this crate. Is there a well-understood solution already? Perhaps other type-checkers can catch unused return values (like Rust does with
#[must_use]
), or linters/linter plugins which would provide such functionality. I see issues considering adding this to mypy but they remain open and unimplemented.What do others do? Is the best solution solution to only use
Result
when I have a value to return in the success case?The text was updated successfully, but these errors were encountered: