-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Decorators confuse E1120 analysis #259
Comments
Original comment by Sylvain Thénault (BitBucket: sthenault, GitHub: @sthenault?): Removing version: 1.1 (automated comment) |
Original comment by Scott Stanton (BitBucket: scott_stanton_veeva): This is very annoying if you are using the Google AppEngine ndb decorators like ndb.transactional(). The decorator is generated by @utils.decorator which converts a function to a decorator. E1120 ends up thinking the decorator arguments are required, so every use of @transactional() generates an error. |
Original comment by Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore): Yeah, ideally this would have been fixed a long time ago. There are many issues and not enough manpower to provide a fix in time for all of them. The only promise I can make right now is that I'll try to target this for fixing in 1.6, since 1.5 is almost ready for launching. |
Comments moved here from #207. Here is a minimal example to reproduce the issue: def helper(fun):
def wrapper(b):
return fun('helper', b)
return wrapper
@helper
def simple(a, b):
print a, b
simple('test')
Here is the same example with the decorator replaced with method composition: def helper(fun):
def wrapper(b):
return fun('helper', b)
return wrapper
def hard(a, b):
print a, b
simple = helper(hard)
simple('test')
To prove that pylint is not simply skipping the signature checking for method composition: def helper(fun):
def wrapper(b):
return fun('helper', b)
return wrapper
def hard(a, b):
print a, b
simple = helper(hard)
simple('helper?', 'test')
The issue is not that pylint is incapable of inferring the signature of generated methods, but rather that pylint lacks the instruction to treat decorators as the composed functions they are. This issue seems to stem from the core AST module leaving it up to the consumer to resolve the signature produced by applying the It should be sufficient to detect when a function node has decorators and substitute it with the return value(s?) of the first decorator. I think it would be generally useful to determine the resulting signature in asteroid. Maybe an attribute like |
Thanks @deckar01. Converting the decorator to simple function call did work. |
Any change with this? |
This is still broken as of pylint 1.7.1, astroid 1.5.3. |
What about following code (based on deckar01's above example) which gives false positive too-many-function-args error: def helper(fun):
def wrapper(a, b, *args, **kwargs):
print "helper wrapper: a={}".format(a)
return fun(b, *args, **kwargs)
return wrapper
@helper
def simple(b, c):
print "simple: b={} c={}".format(b, c)
simple('argentina', 'brazil', 'china') Its output is:
And pylint false positive error is:
Thanks, |
Is this still broken? |
Hey folks, this issue is not fixed yet, as it is still opened. I can't promise when it's going to be fixed though. |
pls, do something, this is ugly for the code |
This is marked as closed but I still see this issue in pylint 2.5.3. Am I missing something? |
I am still having a false-positive with hypothesis.strategies.composite in pylint 2.5.3. |
Same issue with
|
@isaacnorman82 @tmattha @bionicles |
this made me rage, but i finally fixed it, so here's a fix for the next frustrated person
/pylintrc
|
This issue become too messy. I lock it. If you are facing a problem that looks similar please open a new issue that refers this one if necessary. |
Originally reported by: the mulhern (BitBucket: the_mulhern)
Here's the example:
The analysis reports
"No value passed for parameter 'param' in function call (no-value-for-parameter)"
This is incorrect, since the actual function being called is the new_func manufactured
by the decorator, and that function does not require the parameter 'param'.
You can work around this by giving param a default value, (which will never be used).
The text was updated successfully, but these errors were encountered: