tensorbay.utility.attr

AttrsMixin and Field class.

AttrsMixin provides a list of special methods based on field configs.

Field is a class describing the attr related fields.

class tensorbay.utility.attr.Field(*, is_dynamic: bool, key: Union[str, None, Callable[[str], str]], default: Any, error_message: Optional[str], loader: Optional[Callable[[Any], Any]], dumper: Optional[Callable[[Any], Any]])[source]

Bases: object

A class to identify attr fields.

Parameters
  • is_dynamic – Whether attr is a dynamic attr.

  • key – Display value of the attr in contents.

  • default – Default value of the attr.

  • error_message – The custom error message of the attr.

  • loader – The custom loader of the attr.

  • dumper – The custom dumper of the attr.

class tensorbay.utility.attr.BaseField(key: Optional[str])[source]

Bases: object

A class to identify fields of base class.

Parameters

key – Display value of the attr.

class tensorbay.utility.attr.AttrsMixin[source]

Bases: object

AttrsMixin provides a list of special methods based on attr fields.

Examples

box2d: Box2DSubcatalog = attr(is_dynamic=True, key=”BOX2D”)

tensorbay.utility.attr.attr(*, is_dynamic: bool = False, key: Union[str, None, Callable[[str], str]] = <function <lambda>>, default: Any = Ellipsis, error_message: Optional[str] = None, loader: Optional[Callable[[Any], Any]] = None, dumper: Optional[Callable[[Any], Any]] = None) Any[source]

Return an instance to identify attr fields.

Parameters
  • is_dynamic – Determine if this is a dynamic attr.

  • key – Display value of the attr in contents.

  • default – Default value of the attr.

  • error_message – The custom error message of the attr.

  • loader – The custom loader of the attr.

  • dumper – The custom dumper of the attr.

Raises

AttrError – Dynamic attr cannot have default value.

Returns

A Field instance containing all attr fields.

tensorbay.utility.attr.attr_base(key: Optional[str] = None) Any[source]

Return an instance to identify base class fields.

Parameters

key – Display value of the attr.

Returns

A BaseField instance containing all base class fields.

tensorbay.utility.attr.upper(name: str) str[source]

Convert the name value to uppercase.

Parameters

name – name of the attr.

Returns

The uppercase value.

tensorbay.utility.attr.camel(name: str) str[source]

Convert the name value to camelcase.

Parameters

name – name of the attr.

Returns

The camelcase value.