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: For a specified function/method sourced from a specified module, make a specified non-required argument mandatory as a keyword argument. #15225

Open
andyscho opened this issue Jan 2, 2025 · 0 comments
Labels
needs-decision Awaiting a decision from a maintainer rule Implementing or modifying a lint rule

Comments

@andyscho
Copy link

andyscho commented Jan 2, 2025

Rule

For a user-configured (module, function, argument name), enforce that a non-required argument gets supplied. For instance, if a user configures the validate argument in pandas.merge to always be mandatory, the rule would flag if someone passes pandas.merge(df1, df2) without the validate argument.

Example Use Case / Motivation

Making the validate argument for pandas.merge functions/methods mandatory.

Some reasoning from this post:

Of course, many of you can say that the source problem is the duplication in the merge keys itself and it is better simply to check for duplication before performing any merge. However, this is something that we can forget to do and it is better to ALWAYS add parameter validateto the pandas.merge , since it is just 2 words to add to your code. Of course, you need to specify the validation type (“one_to_one”, “one_to_many”, etc), however, I always go with “one_to_one” as a default option, and when it raises an exception, only then I start thinking that maybe I need to change validation type

This particular use case could be hardcoded as a new rule in pandas-vet, but it would be nice to do something more general since the core functionality seems clearly useful when dealing with various third-party libraries. Having it as a ruff rule configuration entry seems nicer than wrapping third-party method/function calls to make the arguments mandatory whenever you'd want to do this.

Configuration

I am envisioning something like the banned-api configuration, allowing for specifying (1) a module qualified name base import path, (2) the name of a function, and (3) arguments to be enforced to be present.

Implementation

I am envisioning something like pandas-use-of-inplace-argument, but using the configured module names, function names, and argument names instead of "pandas", "drop", and "inplace", and then just enforcing that the argument is present in the keywords.

@dhruvmanila dhruvmanila added rule Implementing or modifying a lint rule needs-decision Awaiting a decision from a maintainer labels Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-decision Awaiting a decision from a maintainer rule Implementing or modifying a lint rule
Projects
None yet
Development

No branches or pull requests

2 participants