factory_boy
factory_boy copied to clipboard
`FuzzyAttribute` actually should be named as `FuzzyFunction`
The problem
There is LazyFunction (takes callable, without args) and LazzyAttribute (takes callable with one argument - self). But only one fuzzy class - FuzzyAttribute, which actually takes the same as LazyFunction.
Proposed solution
I would like to see FuzzyAttribute that takes callable and argument self in it, and fix this fuzzy naming in fuzzy functions.
Agreed on principle. There needs to be a deprecation period for this transition, as many codebases rely on FuzzyAttribute signature. The outline should be:
- Create a
FuzzyFunctionand deprecateFuzzyAttribute(raise a deprecation warning when it’s used, suggesting to renameFuzzyAttributetoFuzzyFunction) - On the next major version, remove
FuzzyAttribute - On the next version, introduce back
FuzzyAttribute, and pass its fuzzer the instance being built (argument self)
Or just check if the given callable takes no arguments, if true - raise a warning.
That's a good suggestion indeed, although the existing fuzzy module only provides declaration that are totally isolated from the existing factory.
The implementation I envision is:
- Add a new
factory.fuzzy.FuzzyFunction, which mirrors the currentfactory.fuzzy.FuzzyAttribute; - Add some logic in
factory.fuzzy.FuzzyAttribute to provide aDeprecationWarning` if the provided callable takes no parameter; - Update the documentation.
It could be more detailed:
- Rename
FuzzyAttributetoFuzzyFunction. - Add new implementation of
FuzzyFunction, which accepts only a callable with one argument. - Proxy all logic from
FuzzyFunctiontoFuzzyAttribute(and raise warning) if the given callable is without arguments (check this withinspect.signature). - Update the documentation.
These all (of course) in one PR, or even one commit.
I will do this, when I will have some free time. It's very doubtful, that it will be soon, so if someone wants to implement it right now - you're free to do this.
I will do this, when I will have some free time. It's very doubtful, that it will be soon, so if someone wants to implement it right now - you're free to do this.
Not in this year 100%, maybe next too.