FactoryBoy / factory_boy

A test fixtures replacement for Python
https://factoryboy.readthedocs.io/
MIT License
3.51k stars 396 forks source link

Add support for Ruff `FBT001`: `flake8-boolean-trap` #1080

Open Natim opened 5 months ago

Natim commented 5 months ago

The problem

Please use named parameter in the save method so that we can activate

https://github.com/FactoryBoy/factory_boy/blob/d6349de49b647bb8b7f5d620757a919463f27f7e/factory/declarations.py#L683-L684

Proposed solution

        return self.function(
            instance, create=create, extracted=context.value, **context.extra)

Extra notes

Checks for the use of boolean positional arguments in function definitions, as determined by the presence of a bool type hint.

Calling a function with boolean positional arguments is confusing as the meaning of the boolean value is not clear to the caller and to future readers of the code.

The use of a boolean will also limit the function to only two possible behaviors, which makes the function difficult to extend in the future.

rbarrois commented 2 months ago

Hi,

This is a callback endpoint; changing the way we call the function requires every caller to use the same name for the same arguments.

I haven't checked whether the existing usage of those functions "in the wild" adhere to the recommended argument naming; could you look into this?