Skip to content

Commit 62ed2a6

Browse files
committed
Add __repr__ for classes to appear in log messages
1 parent c29fc3d commit 62ed2a6

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
@@ -128,6 +128,9 @@ def update_datatype(self, datatype: DataType[T]) -> None:
128128
for callback in self._update_datatype_callbacks:
129129
callback(datatype)
130130

131+
def __repr__(self):
132+
return f"{self.__class__.__name__}({self._datatype})"
133+
131134

132135
class AttrR(Attribute[T]):
133136
"""A read-only ``Attribute``."""

src/fastcs/controller.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ def register_sub_controller(self, name: str, sub_controller: SubController):
122122
def get_sub_controllers(self) -> dict[str, SubController]:
123123
return self.__sub_controller_tree
124124

125+
def __repr__(self):
126+
return f"""\
127+
{type(self).__name__}({self.path}, {list(self.__sub_controller_tree.keys())})\
128+
"""
129+
125130

126131
class Controller(BaseController):
127132
"""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
@@ -51,3 +51,6 @@ def context(self) -> dict[str, Any]:
5151
for command_name in softioc.command_names
5252
if command_name != "exit"
5353
}
54+
55+
def __repr__(self):
56+
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
@@ -40,3 +40,6 @@ def create_docs(self) -> None:
4040

4141
def create_gui(self) -> None:
4242
PvaEpicsGUI(self._controller_api, self._pv_prefix).create_gui(self.gui)
43+
44+
def __repr__(self):
45+
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)