|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
5 | 5 | import warnings |
6 | | -from collections.abc import Callable |
7 | | -from typing import TYPE_CHECKING, Any |
8 | | - |
9 | | -from cattrs.gen import make_dict_structure_fn |
10 | | - |
11 | | -from baybe.serialization import converter |
12 | | -from baybe.utils.basic import find_subclass, refers_to |
13 | | -from baybe.utils.boolean import is_abstract |
14 | | - |
15 | | -if TYPE_CHECKING: |
16 | | - from baybe.constraints.base import Constraint |
| 6 | +from typing import Any |
17 | 7 |
|
18 | 8 |
|
19 | 9 | def ContinuousLinearEqualityConstraint( |
@@ -62,36 +52,3 @@ def ContinuousLinearInequalityConstraint( |
62 | 52 | kwargs["rhs"] = rhs |
63 | 53 |
|
64 | 54 | return ContinuousLinearConstraint(**kwargs) |
65 | | - |
66 | | - |
67 | | -def structure_constraints(val: dict, cls: type) -> Constraint: |
68 | | - """A structure hook taking care of deprecations.""" # noqa: D401 (imperative mood) |
69 | | - from baybe.constraints.base import Constraint |
70 | | - |
71 | | - # If the given class can be instantiated, only ensure there is no conflict with |
72 | | - # a potentially specified type field |
73 | | - if not is_abstract(cls): |
74 | | - if (type_ := val.pop("type", None)) and not refers_to(cls, type_): |
75 | | - raise ValueError( |
76 | | - f"The class '{cls.__name__}' specified for deserialization " |
77 | | - f"does not match with the given type information '{type_}'." |
78 | | - ) |
79 | | - concrete_cls = cls |
80 | | - |
81 | | - # Otherwise, extract the type information from the given input and find |
82 | | - # the corresponding class in the hierarchy |
83 | | - else: |
84 | | - type_ = val if isinstance(val, str) else val.pop("type") |
85 | | - |
86 | | - if type_ == "ContinuousLinearEqualityConstraint": |
87 | | - return ContinuousLinearEqualityConstraint(**val) |
88 | | - elif type_ == "ContinuousLinearInequalityConstraint": |
89 | | - return ContinuousLinearInequalityConstraint(**val) |
90 | | - |
91 | | - concrete_cls = find_subclass(Constraint, type_) |
92 | | - |
93 | | - # Create the structuring function for the class and call it |
94 | | - fn: Callable = make_dict_structure_fn( |
95 | | - concrete_cls, converter, _cattrs_forbid_extra_keys=True |
96 | | - ) |
97 | | - return fn({} if isinstance(val, str) else val, concrete_cls) |
0 commit comments