Skip to content
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

Warning/Error for unassigned expressions/return values #17069

Open
samskiter opened this issue Mar 27, 2024 · 1 comment
Open

Warning/Error for unassigned expressions/return values #17069

samskiter opened this issue Mar 27, 2024 · 1 comment
Labels

Comments

@samskiter
Copy link

Feature

Adding a warning or error if an expression is not assigned would encourage callers to handle return types and pick up on changes to APIs.

Pitch

Imagine you have this api:

def fleeb_the_foo() -> None:
    print("fleebing")

def main() -> None:
    fleeb_the_foo()

Then you change it later:

def fleeb_the_foo() -> Bool:
    print("I failed to fleeb!")
    return False

def main() -> None:
    fleeb_the_foo() # <<--- a warning or error here!

If you don't want to handle the warning/error:

def fleeb_the_foo() -> Bool:
    print("I failed to fleeb!")
    return False

def main() -> None:
    _ = fleeb_the_foo() # error is suppressed

This is already implemented to some degree with pylint for unassigned expressions with [expression-not-assigned]

str(42) == "42"  # [expression-not-assigned]
@samskiter
Copy link
Author

I should also mention that there is precedent for this in order languages (C++ [[nodiscard]] and Swift: https://www.avanderlee.com/swift/discardableresult/)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant