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

[New Rule] unnecessary argument defaults #165

Open
danieleades opened this issue Dec 31, 2022 · 0 comments
Open

[New Rule] unnecessary argument defaults #165

danieleades opened this issue Dec 31, 2022 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@danieleades
Copy link

Explanation

Functions that are not part of the public API which have default values for arguments, but which are never used without specifying values for those arguments, can be simplified by removing the default values.

i'm working in a large, public python codebase. I have a general feeling that this codebase has massive overuse of argument defaults in methods and I would love to lint for this. This happens in a couple of different ways-

  • a non-public function has many arguments with default values, however it is never called without fully-specifying the default values anywhere
  • functions that repeatedly delegate to lower-level functions, but repeat the default arguments redundantly at every level in the hierarchy

it's the second case here that causes the biggest headaches in this particular codebase. The function signatures are very noisy. Also (in my case) the default value is almost always None, and it takes some serious archaeology to try and figure out what it means to leave out any particular arg (None is often semantically different to not None).

Example

Bad

def public_method(arg1: Optional[str] = None, arg2: str = "some string"):
    module_method(arg1, arg2)

def module_method(arg1: Optional[str] = None, arg2: str = "some string"):
    submodule_method(arg1, arg2)

def submodule_method(arg1: Optional[str] = None, arg2: str = "some string"):
    ...

Good

def public_method(arg1: Optional[str] = None, arg2: str = "some string"):
    module_method(arg1, arg2)

def module_method(arg1: Optional[str], arg2: str):
    submodule_method(arg1, arg2)

def submodule_method(arg1: Optional[str], arg2: str):
    ...
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

No branches or pull requests

2 participants