MCPcopy
hub / github.com/python-attrs/attrs / Factory

Class Factory

src/attr/_make.py:3029–3065  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

3027
3028
3029class 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 = [

Callers 14

test_factory_sugarMethod · 0.90
CClass · 0.90
test_none_factoryMethod · 0.90
test_no_init_defaultMethod · 0.90
test_no_init_orderMethod · 0.90
CClass · 0.90
test_factory_hashableMethod · 0.90
attribFunction · 0.85

Calls

no outgoing calls

Tested by 9

test_factory_sugarMethod · 0.72
test_none_factoryMethod · 0.72
test_no_init_defaultMethod · 0.72
test_no_init_orderMethod · 0.72
test_factory_hashableMethod · 0.72