add custom repr to AxisTriple so they print nicer in the logging output
This commit is contained in:
parent
0c30d96906
commit
b74d098115
@ -134,7 +134,7 @@ def NormalizedAxisRange(minimum, maximum):
|
|||||||
return NormalizedAxisTriple(minimum, None, maximum)
|
return NormalizedAxisTriple(minimum, None, maximum)
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass(frozen=True, order=True)
|
@dataclasses.dataclass(frozen=True, order=True, repr=False)
|
||||||
class AxisTriple(Sequence):
|
class AxisTriple(Sequence):
|
||||||
"""A triple of (min, default, max) axis values.
|
"""A triple of (min, default, max) axis values.
|
||||||
|
|
||||||
@ -169,6 +169,11 @@ class AxisTriple(Sequence):
|
|||||||
def _replace(self, **kwargs):
|
def _replace(self, **kwargs):
|
||||||
return dataclasses.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
|
@classmethod
|
||||||
def expand(
|
def expand(
|
||||||
cls,
|
cls,
|
||||||
@ -217,7 +222,7 @@ class AxisTriple(Sequence):
|
|||||||
return dataclasses.replace(self, default=default)
|
return dataclasses.replace(self, default=default)
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass(frozen=True, order=True)
|
@dataclasses.dataclass(frozen=True, order=True, repr=False)
|
||||||
class NormalizedAxisTriple(AxisTriple):
|
class NormalizedAxisTriple(AxisTriple):
|
||||||
"""A triple of (min, default, max) normalized axis values."""
|
"""A triple of (min, default, max) normalized axis values."""
|
||||||
|
|
||||||
@ -248,6 +253,9 @@ class _BaseAxisLimits(Mapping[str, AxisTriple]):
|
|||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return f"{type(self).__name__}({self._data!r})"
|
return f"{type(self).__name__}({self._data!r})"
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return str(self._data)
|
||||||
|
|
||||||
def pinnedLocation(self) -> Dict[str, float]:
|
def pinnedLocation(self) -> Dict[str, float]:
|
||||||
"""Return a location dict with only the pinned axes."""
|
"""Return a location dict with only the pinned axes."""
|
||||||
return {k: v.default for k, v in self.items() if v.minimum == v.maximum}
|
return {k: v.default for k, v in self.items() if v.minimum == v.maximum}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user