Stores a factory callable. If passed as the default value to `attrs.field`, the factory is used to generate a new value. Args: factory (typing.Callable): A callable that takes either none or exactly one mandatory positional argument depending on *ta
| 3027 | |
| 3028 | |
| 3029 | class Factory: |
| 3030 | """ |
| 3031 | Stores a factory callable. |
| 3032 | |
| 3033 | If passed as the default value to `attrs.field`, the factory is used to |
| 3034 | generate a new value. |
| 3035 | |
| 3036 | Args: |
| 3037 | factory (typing.Callable): |
| 3038 | A callable that takes either none or exactly one mandatory |
| 3039 | positional argument depending on *takes_self*. |
| 3040 | |
| 3041 | takes_self (bool): |
| 3042 | Pass the partially initialized instance that is being initialized |
| 3043 | as a positional argument. |
| 3044 | |
| 3045 | .. versionadded:: 17.1.0 *takes_self* |
| 3046 | """ |
| 3047 | |
| 3048 | __slots__ = ("factory", "takes_self") |
| 3049 | |
| 3050 | def __init__(self, factory, takes_self=False): |
| 3051 | self.factory = factory |
| 3052 | self.takes_self = takes_self |
| 3053 | |
| 3054 | def __getstate__(self): |
| 3055 | """ |
| 3056 | Play nice with pickle. |
| 3057 | """ |
| 3058 | return tuple(getattr(self, name) for name in self.__slots__) |
| 3059 | |
| 3060 | def __setstate__(self, state): |
| 3061 | """ |
| 3062 | Play nice with pickle. |
| 3063 | """ |
| 3064 | for name, value in zip(self.__slots__, state): |
| 3065 | setattr(self, name, value) |
| 3066 | |
| 3067 | |
| 3068 | _f = [ |
no outgoing calls