pylint error on decorated `name` argument
See original GitHub issuepylint error on decorated name
argument
Due to the way the name
argument is injected into some functions with a decorator, such as pyinfra.operations.server.shell
, we get a pylint error like:
deploy/deploy.py:3:0: E1123: Unexpected keyword argument 'name' in function call (unexpected-keyword-arg)
To Reproduce
deploy.py
:
from pyinfra.operations import server
server.shell(
name='Run command',
commands=['echo "1234"']
)
pylint deploy.py
Expected behavior No pylint errors
Meta
System: Linux Platform: Linux-5.8.11-1-MANJARO-x86_64-with-glibc2.2.5 Release: 5.8.11-1-MANJARO Machine: x86_64 pyinfra: v1.2.1 Executable: /home/user/workspace/common/venv/bin/pyinfra Python: 3.8.5 (CPython, GCC 10.2.0)
- pip installed
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Dealing with linter errors caused by dynamically adding ...
In a nutshell: the dynamic argument passed to my function is used by the decorator and NOT the decorated function. But I get...
Read more >invalid-name / C0103 - Pylint 2.16.0-dev documentation
Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...). Problematic code: class cat: # [invalid-name] def ......
Read more >arguments-renamed / W0237 - Pylint 2.16.0-dev documentation
Description: Used when a method parameter has a different name than in the implemented interface or in an overridden method. Created by the...
Read more >Pylint features - Pylint 2.16.0-dev documentation
Redefining argument with the local name %r Used when a local name is redefining an argument, which might suggest a potential error. This...
Read more >Messages control - Pylint 2.16.0-dev documentation
C convention related checks · R refactoring related checks · W various warnings · E errors, for probable bugs in the code ·...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hm. I can’t replicate this (the error) with either
mypy
orpylint
; using the following example:This passes with both tools as the decorator seems to effectively disable all type checking on the function args as it interprets them as
*args, **kwargs
. So this is useless but also should not be raising the original error here?Regarding fixing typing properly in the future I had one idea - we could (ab)use stub files to force type checkers into including all the global arguments as valid types. Ie by generating (possibly as part of package install?) stub files alongside operation files that type annotate the op functions un-decorated; ie:
This would a) get around the Python 3.10 requirement for
ParamSpec
and b) get aroundParamSpec
’s inability to extend keyword arguments (currently).Annotations could simply be inlined everywhere in the codebase, including operations, and the stub generator would use these combined with the global arguments to generate stubs for operation modules.
So flake8 doesn’t do type checking which has prevented this being an issue before! There’s currently a PR/branch (https://github.com/Fizzadar/pyinfra/pull/472) tracking implementation of type checking using mypy.
The operation functions are particularly annoying as they all accept a list of global arguments, defined here which is a bit of a nightmare for typing.
I think long run the right approach is to move these into the operation function definition itself, will need to deduplicate that with the deploy function also (possibly by way of a decorator decorator!).