question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Forbid too many different positional arguments passing

See original GitHub issue

Rule request

Thesis

If function gets many arguments they all should be keyword.

Bad:

get_report('daily', date_from, date_to, 'pdf', False)

Good:

get_report(period='daily', since=date_from, till=date_to, extension='pdf', cache=False)

Exceptions:

  1. 1-2 positional parameters:
    get_report(since, till)
    
  2. Function get *args, so all arguments have the same meaning:
    max(1, 2, 3, 12, 9)
    

Reasoning

It’s difficult to read. You can regulate it for your code via keyword-only arguments, but in big project it will be useful to forget it for third-party functions calls too.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
orsiniumcommented, Nov 19, 2018

As possible solution we can block positional args of different types.

Bad:

some_func(1, 'test', [3, 4])

Good:

some_func(1, 2, 3, 4)
some_func('lol', 'lal', 'test')
0reactions
sobolevncommented, Nov 27, 2018

Correct implementation is not possible, I have researched this topic.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python: avoiding Pylint warnings about too many arguments
My point is about having to pass many variables to the extracted function and avoiding the pylint warning if possible (without explicitly making ......
Read more >
Python: Keyword arguments and "Functions, methods and ...
Maybe we could consider that the problem of passing too many positional arguments to a function call is a separate problem.
Read more >
too-many-arguments / R0913 - Pylint 2.16.0-dev documentation
too -many-arguments / R0913#. Message emitted: Too many arguments (%s/%s). Description: Used when a function or method takes too many arguments.
Read more >
Effective Python: 4 Best Practices for Function Arguments
Like most other programming languages, calling a function in Python allows for passing arguments by position.
Read more >
Argument Passing in Airflow's Operator Inheritance ... - Medium
A review of *args, **kwargs, and argument passing when extending a class ... If there are too many instance variables, consider breaking up ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found