utils.attrs¶
Danger
You probably don't want to touch these functions unless you are modifying the library itself.
Functions providing converters and validators for attrs classes.
attach_parent ¶
attach_parent(item, attr, value)
Attach parent object to a NameSpecification.
Intended to be called from on_setattr of an attrs.field.
auto_validate_types ¶
auto_validate_types(cls, fields)
Add validators to attrs classes based on their type annotations.
Intended to be used with the field_transformer parameter of @attrs.define.
Supported type annotations
- str, int
FileReferenceand derived classesName,NameSpecificationMarkupTextOptional[<type>]list[<type>]tuple[<type>, ...]
The purpose of this function is to reduce the need for explicitly adding validators to the classes in acl_anthology.collections and acl_anthology.people.person. It does not automatically validate classes defined in acl_anthology.collections, as that would lead to circular imports.
See also: https://www.attrs.org/en/stable/extending.html#transform-fields
date_to_str ¶
date_to_str(value)
Convert a date or datetime object to str (in ISO format), and leave unchanged otherwise.
Intended to be used as a converter for attrs.field.
int_to_str ¶
int_to_str(value)
Convert an int to str, and leave unchanged otherwise.
Intended to be used as a converter for attrs.field.
validate_anthology_id_tuple ¶
validate_anthology_id_tuple(cls, attr, value)
Validate that an AnthologyIDTuple has the correct format.