Skip to content

Commit bbe484c

Browse files
committed
Add __repr__ for classes to appear in log messages
1 parent 792a28d commit bbe484c

File tree

7 files changed

+25
-0
lines changed

7 files changed

+25
-0
lines changed

src/fastcs/attributes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ def update_datatype(self, datatype: DataType[T]) -> None:
8282
for callback in self._update_datatype_callbacks:
8383
callback(datatype)
8484

85+
def __repr__(self):
86+
return f"{self.__class__.__name__}({self._datatype})"
87+
8588

8689
class AttrR(Attribute[T, AttributeIORefT]):
8790
"""A read-only ``Attribute``."""

src/fastcs/controller.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ def register_sub_controller(self, name: str, sub_controller: Controller):
185185
def get_sub_controllers(self) -> dict[str, Controller]:
186186
return self.__sub_controller_tree
187187

188+
def __repr__(self):
189+
return f"""\
190+
{type(self).__name__}({self.path}, {list(self.__sub_controller_tree.keys())})\
191+
"""
192+
188193

189194
class Controller(BaseController):
190195
"""Top-level controller for a device.

src/fastcs/controller_api.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,8 @@ def walk_api(self) -> Iterator["ControllerAPI"]:
2929
yield self
3030
for api in self.sub_apis.values():
3131
yield from api.walk_api()
32+
33+
def __repr__(self):
34+
return f"""\
35+
ControllerAPI(path={self.path}, sub_apis=[{", ".join(self.sub_apis.keys())}])\
36+
"""

src/fastcs/transport/epics/ca/transport.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,6 @@ def context(self) -> dict[str, Any]:
5454
for command_name in softioc.command_names
5555
if command_name != "exit"
5656
}
57+
58+
def __repr__(self):
59+
return f"EpicsCATransport({self._pv_prefix})"

src/fastcs/transport/epics/pva/transport.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,6 @@ def create_docs(self) -> None:
4343

4444
def create_gui(self) -> None:
4545
PvaEpicsGUI(self._controller_api, self._pv_prefix).create_gui(self.gui)
46+
47+
def __repr__(self):
48+
return f"EpicsPVATransport({self._pv_prefix})"

src/fastcs/transport/graphql/transport.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ def initialise(
2323

2424
async def serve(self) -> None:
2525
await self._server.serve(self.graphql)
26+
27+
def __repr__(self) -> str:
28+
return f"GraphQLTransport({self.graphql.host}:{self.graphql.port})"

src/fastcs/transport/rest/transport.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ def initialise(
2323

2424
async def serve(self) -> None:
2525
await self._server.serve(self.rest)
26+
27+
def __repr__(self) -> str:
28+
return f"RestTransport({self.rest.host}:{self.rest.port})"

0 commit comments

Comments
 (0)