-
Notifications
You must be signed in to change notification settings - Fork 357
Expand file tree
/
Copy pathv0.py
More file actions
55 lines (43 loc) · 1.73 KB
/
v0.py
File metadata and controls
55 lines (43 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from __future__ import annotations
from typing import TYPE_CHECKING
from ..param_spec import ParamSpec
if TYPE_CHECKING:
from .rundescribertypes import InterDependenciesDict
class InterDependencies: # noqa: PLW1641
# TODO not clear if this should implement __hash__
"""
Object containing the ParamSpecs of a given run
"""
def __init__(self, *paramspecs: ParamSpec) -> None:
for paramspec in paramspecs:
if not isinstance(paramspec, ParamSpec):
raise ValueError(
"Got invalid input. All paramspecs must be "
f"ParamSpecs, but {paramspec} is of type "
f"{type(paramspec)}."
)
self.paramspecs = paramspecs
def __repr__(self) -> str:
output = self.__class__.__name__
tojoin = (str(paramspec) for paramspec in self.paramspecs)
output += f"({', '.join(tojoin)})"
return output
def __eq__(self, other: object) -> bool:
if not isinstance(other, InterDependencies):
return False
ours = sorted(self.paramspecs, key=lambda ps: ps.name)
theirs = sorted(other.paramspecs, key=lambda ps: ps.name)
return ours == theirs
def _to_dict(self) -> InterDependenciesDict:
"""
Return a dictionary representation of this object instance
"""
return {"paramspecs": tuple(ps._to_dict() for ps in self.paramspecs)}
@classmethod
def _from_dict(cls, ser: InterDependenciesDict) -> InterDependencies:
"""
Create an InterDependencies object from a dictionary
"""
paramspecs = [ParamSpec._from_dict(sps) for sps in ser["paramspecs"]]
idp = cls(*paramspecs)
return idp