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

Separate warnings for None-returning functions/methods without annotations #41

Closed
gdude2002 opened this issue Oct 3, 2019 · 3 comments · Fixed by #60
Closed

Separate warnings for None-returning functions/methods without annotations #41

gdude2002 opened this issue Oct 3, 2019 · 3 comments · Fixed by #60
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@gdude2002
Copy link

Description
It would be nice if flake8-annotations could tell the difference between a callable returning None or using return for flow control, and functions that actually return a value.

Rationale/Use Case
I was surprised to see this behaviour at all at first, although it makes sense now that it's been explained to me.

  • Having a separate error code and message specifically mentioning None returns helps to clarify that this is an intentional part of the project's code style
  • Doubtless, there are projects out there that would rather not annotate a None return type (even though this doesn't apply to any Python Discord projects)

Good work on this plugin, by the way. It never occurred to me how useful something like this would be!

@gdude2002 gdude2002 added the enhancement New feature or request label Oct 3, 2019
@sco1
Copy link
Owner

sco1 commented Oct 3, 2019

It's certainly an interesting concept but I don't think this is feasible from within flake8's framework for anything but trivial examples.

The case of cross-file function calls is particularly problematic since flake8 operates on a per-file basis and provides no mechanism to persist information globally for the package being linted, so there is no deterministic way for this plugin to tell if a foo() in return foo() returns anything or not. I'm not comfortable with making the assumption that foo() in this case returns something other than None just because it's being called during a return.

@gdude2002
Copy link
Author

That's an interesting point, and I'm not sure if there could be a decent solution to that one - static code analysis tools generally are expected to operate on single files regardless.

I personally feel like assuming the foo() in return foo() doesn't return None is a fairly safe assumption however, as the use-cases for return being used in this manner while foo() only ever returns a None value are extremely limited - but you probably have a better idea than me of the impact of such an assumption.

@sco1
Copy link
Owner

sco1 commented Nov 30, 2019

After doing some more trawling around the internet I'm still against providing this as the default behavior due to its ambiguity and lack of a deterministic way to statically identify whether the function does or does not explicitly return something.

However, since we already make similar anti-PEP484 concessions for style by providing the capability to suppress missing return annotations by function type, it's worth exploring the level of effort required to add a configuration option that allows suppression of TYP200 level errors if a function either:

  • Has a bare return
  • Lacks a return statement

@sco1 sco1 added this to the v1.2.0 milestone Dec 18, 2019
@sco1 sco1 self-assigned this Jan 2, 2020
@sco1 sco1 mentioned this issue Jan 19, 2020
@sco1 sco1 closed this as completed in #60 Feb 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants