Stores a factory callable. If passed as the default value to `attrs.field`, the factory is used to generate a new value. :param callable factory: A callable that takes either none or exactly one mandatory positional argument depending on *takes_self*. :param bool takes
| 2950 | |
| 2951 | |
| 2952 | class Factory(object): |
| 2953 | """ |
| 2954 | Stores a factory callable. |
| 2955 | |
| 2956 | If passed as the default value to `attrs.field`, the factory is used to |
| 2957 | generate a new value. |
| 2958 | |
| 2959 | :param callable factory: A callable that takes either none or exactly one |
| 2960 | mandatory positional argument depending on *takes_self*. |
| 2961 | :param bool takes_self: Pass the partially initialized instance that is |
| 2962 | being initialized as a positional argument. |
| 2963 | |
| 2964 | .. versionadded:: 17.1.0 *takes_self* |
| 2965 | """ |
| 2966 | |
| 2967 | __slots__ = ("factory", "takes_self") |
| 2968 | |
| 2969 | def __init__(self, factory, takes_self=False): |
| 2970 | """ |
| 2971 | `Factory` is part of the default machinery so if we want a default |
| 2972 | value here, we have to implement it ourselves. |
| 2973 | """ |
| 2974 | self.factory = factory |
| 2975 | self.takes_self = takes_self |
| 2976 | |
| 2977 | def __getstate__(self): |
| 2978 | """ |
| 2979 | Play nice with pickle. |
| 2980 | """ |
| 2981 | return tuple(getattr(self, name) for name in self.__slots__) |
| 2982 | |
| 2983 | def __setstate__(self, state): |
| 2984 | """ |
| 2985 | Play nice with pickle. |
| 2986 | """ |
| 2987 | for name, value in zip(self.__slots__, state): |
| 2988 | setattr(self, name, value) |
| 2989 | |
| 2990 | |
| 2991 | _f = [ |
no outgoing calls
no test coverage detected