astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.
https://docs.astral.sh/ruff
MIT License
32.46k stars 1.08k forks source link

`flake8-boolean-trap.extend-allowed-calls` don't resolve class types #11264

Open clara-bordes opened 6 months ago

clara-bordes commented 6 months ago

I am actually working on fixing the rule boolean-positional-value-in-call (FBT003) on a code repository.

I need to allow this rule for some functions. For that, at the end of my config file "pyproject.toml", I have added:

[lint.flake8-boolean-trap]
extend-allowed-calls = ["LibName.className.functionName"]

My issue here is that in my code repository, we call the function "LibName.className.functionName" through a variable, as following:

from LibName import ClassName

with ClassName("[Description]") as variable:
       variable.functionName(...)

On such code, the rule FBT003 is still applied in spite of the "extend-allowed-calls" option.

Is the "extend-allowed-calls" option only works for direct function calls?

charliermarsh commented 6 months ago

Yes, that setting doesn't support resolution to the base type. It won't trace variable back to LibName.ClassName.

charliermarsh commented 6 months ago

I'd suggest just disabling the rule, but we'll probably support this at some point in the future.

flying-sheep commented 3 months ago

would be nice to support wildcards in the meantime. E.g. I think all methods called like .fill(True) are probably fine.