fqr.objects.metas.utl module

Metaclass module utility functions.

parse_new_annotations(__namespace: dict[str | string[StringType], Any], __annotations: dict[string[snake_case], Any], __module: str, __slots: list[string[snake_case]], __fields: dict[string[snake_case], AnyField[lib.t.Any]], __base_fields: set[string[snake_case]]) tuple[list[string[snake_case]], dict[string[snake_case], AnyField[lib.t.Any]]] | Never

Parse passed __annotations for valid Fields not otherwise explicitly mapped in __namespace.

Returns updated __slots and __fields.

Passed __namespace will be mutated inplace, removing all key, value pairs where keys overlap with those in __annotations.

Raises a corresponding exception if class definition invalid.

parse_new_namespace(__namespace: dict[str | string[StringType], Any], __annotations: dict[string[snake_case], Any], __module: str, __slots: list[string[snake_case]], __fields: dict[string[snake_case], AnyField[lib.t.Any]]) tuple[list[str], list[string[snake_case]], dict[string[snake_case], AnyField[lib.t.Any]]] | Never

Parse passed __namespace for valid Fields.

Returns a list[str] of default values, as well as updated __slots and __fields.

Raises a corresponding exception if class definition invalid.

get_enumerations_from_fields(fields: dict[string[snake_case], AnyField[lib.t.Any]]) dict[string[snake_case], tuple[bool | float | int | None | str, ...]]

Return dict containing all enums for object.

Automatically appends None to any enums for an Optional type.

get_fields_for_hash(__fields: dict[string[snake_case], AnyField[lib.t.Any]]) tuple[string[snake_case], ...]

Filter to set of minimum fields required to compute a unique hash for their owner object.

Fields used must be of primitive types, for these purposes: bool | float | int | None | str.

Fields ending in the following will be used [in the following order of precedence]:

  1. '*id' | '*key'

  2. '*name'

For example, for an object with fields 'id_' and '_common_name_', this function would return ('id_', ), as 'id_' takes precedence over '_common_name_'.

If no fields are named in ways that suggest they can be used to determine the uniqueness of the object, all fields will instead be returned.

is_public_field(f: str) bool

Return if field name is public.

is_valid_keyword(f: str) bool

Return if field name is allowed.