Rule to prohibit closures?
Opened this issue · 1 comments
Sometimes I accidentally write a python script like this:
import polars as pl
def f(data_1: pl.DataFrame):
return data_1.join(data_2, on="...")
if __name__ == "__main__":
data_1 = pl.DataFrame(...)
data_2 = pl.DataFrame(...)
result = f(data_1)
It can be easy to miss the mistake when f
has more arguments.
I understand that sometimes people deliberately define global constants, and read from those constants without passing them into a function. But it would be nice to have an option to prohibit that pattern, and force all variables to be passed in explicitly. Is it feasible or desirable for ruff to make an optional rule like that?
Restricting any use of closures is too restricting with Ruff's current rule model. We might be able to support a rule like this once #1774 has been completed.
Even then, restricting all closures seems fairly strict and it would probably be good to come up with a more specific heuristic to reduce the false positives where the use of closures is intended.