Skip to content

Commit

Permalink
add custom repr to AxisTriple so they print nicer in the logging output
Browse files Browse the repository at this point in the history
  • Loading branch information
anthrotype committed Oct 21, 2022
1 parent 0c30d96 commit b74d098
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Lib/fontTools/varLib/instancer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -169,6 +169,11 @@ def __len__(self):
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,
Expand Down Expand Up @@ -217,7 +222,7 @@ def populateDefault(self, fvarAxisDefault) -> "AxisTriple":
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."""

Expand Down Expand Up @@ -248,6 +253,9 @@ def __len__(self) -> int:
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}
Expand Down

0 comments on commit b74d098

Please sign in to comment.