fqr.objects.lib module¶
Objects imports.
- dataclass_transform(*, eq_default: bool = True, order_default: bool = False, kw_only_default: bool = False, frozen_default: bool = False, field_specifiers: tuple[type[Any] | Callable[[...], Any], ...] = (), **kwargs: Any) _IdentityCallable¶
Decorator to mark an object as providing dataclass-like behaviour.
The decorator can be applied to a function, class, or metaclass.
Example usage with a decorator function:
.. code::
@dataclass_transform() def create_model[T](cls: type[T]) -> type[T]:
… return cls
@create_model class CustomerModel:
id: int name: str
On a base class:
.. code::
@dataclass_transform() class ModelBase: …
- class CustomerModel(ModelBase):
id: int name: str
On a metaclass:
.. code::
@dataclass_transform() class ModelMeta(type): …
class ModelBase(metaclass=ModelMeta): …
- class CustomerModel(ModelBase):
id: int name: str
The
CustomerModelclasses defined above will be treated by type checkers similarly to classes created with@dataclasses.dataclass. For example, type checkers will assume these classes have__init__methods that acceptidandname.The arguments to this decorator can be used to customize this behavior:
eq_defaultindicates whether theeqparameter is assumed to be
TrueorFalseif it is omitted by the caller. *order_defaultindicates whether theorderparameter is assumed to be True or False if it is omitted by the caller. *kw_only_defaultindicates whether thekw_onlyparameter is assumed to be True or False if it is omitted by the caller. *frozen_defaultindicates whether thefrozenparameter is assumed to be True or False if it is omitted by the caller. *field_specifiersspecifies a static list of supported classes or functions that describe fields, similar todataclasses.field(). * Arbitrary other keyword arguments are accepted in order to allow for possible future extensions.At runtime, this decorator records its arguments in the
__dataclass_transform__attribute on the decorated object. It has no other runtime effect.See PEP 681 for more details.
- class TypeVarTuple¶
Bases:
objectType variable tuple. A specialized form of type variable that enables variadic generics.
The preferred way to construct a type variable tuple is via the dedicated syntax for generic functions, classes, and type aliases, where a single ‘*’ indicates a type variable tuple:
.. code::
For compatibility with Python 3.11 and earlier, TypeVarTuple objects can also be created as follows:
.. code::
Ts = TypeVarTuple(‘Ts’) # Can be given any name
Just as a TypeVar (type variable) is a placeholder for a single type, a TypeVarTuple is a placeholder for an arbitrary number of types. For example, if we define a generic class using a TypeVarTuple:
.. code::
class C[*Ts]: …
Then we can parameterize that class with an arbitrary number of type arguments:
.. code::
C[int] # Fine C[int, str] # Also fine C[()] # Even this is fine
For more details, see PEP 646.
Note that only TypeVarTuples defined in the global scope can be pickled.