From fc2e151d71bd74a45bc7d7e64b8f6eafb7cd6e46 Mon Sep 17 00:00:00 2001 From: Nathaniel Starkman Date: Sun, 29 Dec 2024 11:14:20 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=84=20ui(frames):=20improve=20Coordina?= =?UTF-8?q?te=20str=20repr=20(#324)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/coordinax/_src/frames/coordinate.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/coordinax/_src/frames/coordinate.py b/src/coordinax/_src/frames/coordinate.py index 98f2e5d9..d982b401 100644 --- a/src/coordinax/_src/frames/coordinate.py +++ b/src/coordinax/_src/frames/coordinate.py @@ -97,8 +97,9 @@ def __repr__(self) -> str: """ # NOTE: this is necessary because equinox __repr__ isn't great - str_fs = ",\n".join(indent(f"{k}={v}", " ") for k, v in field_items(self)) - return f"{type(self).__name__}(\n{str_fs}\n)" + cls_name = type(self).__name__ + str_fs = ",\n".join(indent(f"{k}={v!r}", " ") for k, v in field_items(self)) + return f"{cls_name}(\n{str_fs}\n)" _repr_latex_ = __repr__ # TODO: implement this @@ -116,7 +117,9 @@ def __str__(self) -> str: ) """ - return self.__repr__() + # NOTE: this is necessary because equinox __repr__ isn't great + str_fs = ",\n".join(indent(f"{k}={v}", " ") for k, v in field_items(self)) + return f"{type(self).__name__}(\n{str_fs}\n)" ############################################################################## @@ -202,6 +205,9 @@ class Coordinate(AbstractCoordinate): converter=Unless(AbstractReferenceFrame, TransformedReferenceFrame.from_) ) + # =============================================================== + # Vector API + @override def _dimensionality(self) -> int: """Dimensionality of the vector. @@ -220,9 +226,6 @@ def _dimensionality(self) -> int: # TODO: Space is currently not implemented. return self.data._dimensionality() # noqa: SLF001 - # =============================================================== - # Vector API - @dispatch def __getitem__(self: "Coordinate", index: Any) -> "Coordinate": """Return Coordinate, with indexing applied to the data.