Search code examples
pythoncontinuous-integrationlint

Disallow Python Variadic Arguments


Is there any linting tool in existence that is capable of disallowing the use of variadic arguments in functions (*args, **kwargs), without needing to write a plugin?


Solution

  • No, whilst absence of evidence is not evidence of absence, I did a pretty thorough search for this a while ago and found nothing. ruffs linter pulls in rules from most of the major linters, (pflakes, flake8, black, isort) it doesn't have a rule for it.

    I know the pain of this... I've seen some code written by well meaning untrained programmers that use **kwargs as the signature for every function. I think the idea is to avoid having to change the signature of their functions, but you end up with code that is impossible to reason about or type check.

    Unfortunately, there are many valid/unavoidable use cases for them, that a hard "no" by a linter hasn't become a thing.

    In our case we solved this issue by first doing a bunch of education/training and then by using mypy with -no-untyped-defs to enforce typing of function definitions. The difficulty of typing of **kwargs and *args was enough "encouragement" to cement the change.