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 CustomerModel classes 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 accept id and name.

The arguments to this decorator can be used to customize this behavior:

  • eq_default indicates whether the eq parameter is assumed to be

True or False if it is omitted by the caller. * order_default indicates whether the order parameter is assumed to be True or False if it is omitted by the caller. * kw_only_default indicates whether the kw_only parameter is assumed to be True or False if it is omitted by the caller. * frozen_default indicates whether the frozen parameter is assumed to be True or False if it is omitted by the caller. * field_specifiers specifies a static list of supported classes or functions that describe fields, similar to dataclasses.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: object

Type 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::
def move_first_element_to_last[T, *Ts](tup: tuple[T, *Ts]) -> tuple[*Ts, T]:

return (*tup[1:], tup[0])

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.