add custom repr to AxisTriple so they print nicer in the logging output

This commit is contained in:
Cosimo Lupo 2022-10-21 18:38:55 +01:00
parent 0c30d96906
commit b74d098115
No known key found for this signature in database
GPG Key ID: DF65A8A5A119C9A8

View File

@ -134,7 +134,7 @@ def NormalizedAxisRange(minimum, maximum):
return NormalizedAxisTriple(minimum, None, maximum)
@dataclasses.dataclass(frozen=True, order=True)
@dataclasses.dataclass(frozen=True, order=True, repr=False)
class AxisTriple(Sequence):
"""A triple of (min, default, max) axis values.
@ -169,6 +169,11 @@ class AxisTriple(Sequence):
def _replace(self, **kwargs):
return dataclasses.replace(self, **kwargs)
def __repr__(self):
return (
f"({', '.join(format(v, 'g') if v is not None else 'None' for v in self)})"
)
@classmethod
def expand(
cls,
@ -217,7 +222,7 @@ class AxisTriple(Sequence):
return dataclasses.replace(self, default=default)
@dataclasses.dataclass(frozen=True, order=True)
@dataclasses.dataclass(frozen=True, order=True, repr=False)
class NormalizedAxisTriple(AxisTriple):
"""A triple of (min, default, max) normalized axis values."""
@ -248,6 +253,9 @@ class _BaseAxisLimits(Mapping[str, AxisTriple]):
def __repr__(self) -> str:
return f"{type(self).__name__}({self._data!r})"
def __str__(self) -> str:
return str(self._data)
def pinnedLocation(self) -> Dict[str, float]:
"""Return a location dict with only the pinned axes."""
return {k: v.default for k, v in self.items() if v.minimum == v.maximum}