_funcs
asdict(inst, recurse=True, filter=None, dict_factory=dict, retain_collection_types=False, value_serializer=None)
Return the attrs
attribute values of inst as a dict.
Optionally recurse into other attrs
-decorated classes.
:param inst: Instance of an attrs
-decorated class. :param bool recurse: Recurse into classes that are also attrs
-decorated. :param callable filter: A callable whose return code determines whether an attribute or element is included (True
) or dropped (False
). Is called with the attr.Attribute
as the first argument and the value as the second argument. :param callable dict_factory: A callable to produce dictionaries from. For example, to produce ordered dictionaries instead of normal Python dictionaries, pass in collections.OrderedDict
. :param bool retain_collection_types: Do not convert to list
when encountering an attribute whose type is tuple
or set
. Only meaningful if recurse
is True
. :param Optional[callable] value_serializer: A hook that is called for every attribute or dict key/value. It receives the current instance, field and value and must return the (updated) value. The hook is run after the optional filter has been applied.
:rtype: return type of dict_factory
:raise attr.exceptions.NotAnAttrsClassError: If cls is not an attrs
class.
.. versionadded:: 16.0.0 dict_factory .. versionadded:: 16.1.0 retain_collection_types .. versionadded:: 20.3.0 value_serializer
Source code in client/ayon_fusion/vendor/attr/_funcs.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
assoc(inst, **changes)
Copy inst and apply changes.
:param inst: Instance of a class with attrs
attributes. :param changes: Keyword changes in the new copy.
:return: A copy of inst with changes incorporated.
:raise attr.exceptions.AttrsAttributeNotFoundError: If attr_name couldn't be found on cls. :raise attr.exceptions.NotAnAttrsClassError: If cls is not an attrs
class.
.. deprecated:: 17.1.0 Use evolve
instead.
Source code in client/ayon_fusion/vendor/attr/_funcs.py
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
|
astuple(inst, recurse=True, filter=None, tuple_factory=tuple, retain_collection_types=False)
Return the attrs
attribute values of inst as a tuple.
Optionally recurse into other attrs
-decorated classes.
:param inst: Instance of an attrs
-decorated class. :param bool recurse: Recurse into classes that are also attrs
-decorated. :param callable filter: A callable whose return code determines whether an attribute or element is included (True
) or dropped (False
). Is called with the attr.Attribute
as the first argument and the value as the second argument. :param callable tuple_factory: A callable to produce tuples from. For example, to produce lists instead of tuples. :param bool retain_collection_types: Do not convert to list
or dict
when encountering an attribute which type is tuple
, dict
or set
. Only meaningful if recurse
is True
.
:rtype: return type of tuple_factory
:raise attr.exceptions.NotAnAttrsClassError: If cls is not an attrs
class.
.. versionadded:: 16.2.0
Source code in client/ayon_fusion/vendor/attr/_funcs.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
|
evolve(inst, **changes)
Create a new instance, based on inst with changes applied.
:param inst: Instance of a class with attrs
attributes. :param changes: Keyword changes in the new copy.
:return: A copy of inst with changes incorporated.
:raise TypeError: If attr_name couldn't be found in the class __init__
. :raise attr.exceptions.NotAnAttrsClassError: If cls is not an attrs
class.
.. versionadded:: 17.1.0
Source code in client/ayon_fusion/vendor/attr/_funcs.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
|
has(cls)
Check whether cls is a class with attrs
attributes.
:param type cls: Class to introspect. :raise TypeError: If cls is not a class.
:rtype: bool
Source code in client/ayon_fusion/vendor/attr/_funcs.py
267 268 269 270 271 272 273 274 275 276 |
|
resolve_types(cls, globalns=None, localns=None, attribs=None)
Resolve any strings and forward annotations in type annotations.
This is only required if you need concrete types in Attribute
's type field. In other words, you don't need to resolve your types if you only use them for static type checking.
With no arguments, names will be looked up in the module in which the class was created. If this is not what you want, e.g. if the name only exists inside a method, you may pass globalns or localns to specify other dictionaries in which to look up these names. See the docs of typing.get_type_hints
for more details.
:param type cls: Class to resolve. :param Optional[dict] globalns: Dictionary containing global variables. :param Optional[dict] localns: Dictionary containing local variables. :param Optional[list] attribs: List of attribs for the given class. This is necessary when calling from inside a field_transformer
since cls is not an attrs
class yet.
:raise TypeError: If cls is not a class. :raise attr.exceptions.NotAnAttrsClassError: If cls is not an attrs
class and you didn't pass any attribs. :raise NameError: If types cannot be resolved because of missing variables.
:returns: cls so you can use this function also as a class decorator. Please note that you have to apply it after attr.s
. That means the decorator has to come in the line before attr.s
.
.. versionadded:: 20.1.0 .. versionadded:: 21.1.0 attribs
Source code in client/ayon_fusion/vendor/attr/_funcs.py
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 |
|