factory_boy icon indicating copy to clipboard operation
factory_boy copied to clipboard

`FuzzyAttribute` actually should be named as `FuzzyFunction`

Open PerchunPak opened this issue 1 year ago • 5 comments

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.

PerchunPak avatar Jul 10 '22 19:07 PerchunPak

Agreed on principle. There needs to be a deprecation period for this transition, as many codebases rely on FuzzyAttribute signature. The outline should be:

  1. Create a FuzzyFunction and deprecate FuzzyAttribute (raise a deprecation warning when it’s used, suggesting to rename FuzzyAttribute to FuzzyFunction)
  2. On the next major version, remove FuzzyAttribute
  3. On the next version, introduce back FuzzyAttribute, and pass its fuzzer the instance being built (argument self)

francoisfreitag avatar Jul 11 '22 09:07 francoisfreitag

Or just check if the given callable takes no arguments, if true - raise a warning.

This is how it can be done.

PerchunPak avatar Jul 11 '22 14:07 PerchunPak

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 current factory.fuzzy.FuzzyAttribute;
  • Add some logic in factory.fuzzy.FuzzyAttribute to provide a DeprecationWarning` if the provided callable takes no parameter;
  • Update the documentation.

rbarrois avatar Sep 24 '22 09:09 rbarrois

It could be more detailed:

  1. Rename FuzzyAttribute to FuzzyFunction.
  2. Add new implementation of FuzzyFunction, which accepts only a callable with one argument.
  3. Proxy all logic from FuzzyFunction to FuzzyAttribute (and raise warning) if the given callable is without arguments (check this with inspect.signature).
  4. 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.

PerchunPak avatar Sep 25 '22 06:09 PerchunPak

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.

PerchunPak avatar Dec 22 '22 14:12 PerchunPak