MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / attrib

Function attrib

src/licensedcode/_vendor/attr/_make.py:124–317  ·  view source on GitHub ↗

Create a new attribute on a class. .. warning:: Does *not* do anything unless the class is also decorated with `attr.s`! :param default: A value that is used if an ``attrs``-generated ``__init__`` is used and no value is passed while instantiating or the attr

(
    default=NOTHING,
    validator=None,
    repr=True,
    cmp=None,
    hash=None,
    init=True,
    metadata=None,
    type=None,
    converter=None,
    factory=None,
    kw_only=False,
    eq=None,
    order=None,
    on_setattr=None,
)

Source from the content-addressed store, hash-verified

122
123
124def attrib(
125 default=NOTHING,
126 validator=None,
127 repr=True,
128 cmp=None,
129 hash=None,
130 init=True,
131 metadata=None,
132 type=None,
133 converter=None,
134 factory=None,
135 kw_only=False,
136 eq=None,
137 order=None,
138 on_setattr=None,
139):
140 """
141 Create a new attribute on a class.
142
143 .. warning::
144
145 Does *not* do anything unless the class is also decorated with
146 `attr.s`!
147
148 :param default: A value that is used if an ``attrs``-generated ``__init__``
149 is used and no value is passed while instantiating or the attribute is
150 excluded using ``init=False``.
151
152 If the value is an instance of `attrs.Factory`, its callable will be
153 used to construct a new value (useful for mutable data types like lists
154 or dicts).
155
156 If a default is not set (or set manually to `attrs.NOTHING`), a value
157 *must* be supplied when instantiating; otherwise a `TypeError`
158 will be raised.
159
160 The default can also be set using decorator notation as shown below.
161
162 :type default: Any value
163
164 :param callable factory: Syntactic sugar for
165 ``default=attr.Factory(factory)``.
166
167 :param validator: `callable` that is called by ``attrs``-generated
168 ``__init__`` methods after the instance has been initialized. They
169 receive the initialized instance, the :func:`~attrs.Attribute`, and the
170 passed value.
171
172 The return value is *not* inspected so the validator has to throw an
173 exception itself.
174
175 If a `list` is passed, its items are treated as validators and must
176 all pass.
177
178 Validators can be globally disabled and re-enabled using
179 `get_run_validators`.
180
181 The validator can also be set using decorator notation as shown below.

Callers 14

fieldFunction · 0.85
_transform_attrsFunction · 0.85
make_classFunction · 0.85
_AndValidatorClass · 0.85
VersionInfoClass · 0.85
_MatchesReValidatorClass · 0.85
_ProvidesValidatorClass · 0.85
_OptionalValidatorClass · 0.85
_InValidatorClass · 0.85
_DeepIterableClass · 0.85
_DeepMappingClass · 0.85

Calls 6

callableFunction · 0.85
FactoryClass · 0.85
and_Function · 0.85
_CountingAttrClass · 0.85
pipeFunction · 0.70

Tested by

no test coverage detected