Skip to content

Commit 2eea611

Browse files
committed
Also override __set__ for type checkers
1 parent 83450d9 commit 2eea611

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/ctapipe/core/container.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def __init__(
170170
if default_factory is not None and default is not None:
171171
raise ValueError("Must only provide one of default or default_factory")
172172

173-
# we only specify the Descriptor protocol __get__ here has it helps type checkers
173+
# we only specify the Descriptor protocol __get__ & __set__ here has it helps type checkers
174174
# and IDEs to provide insights on types of container fields. It is not actually used at runtime
175175
# since the ContainerMeta turns Fields into __slots__ based access to member variables.
176176
# 1. When accessed via the class (e.g., MyContainer.foo), only owner present
@@ -184,7 +184,14 @@ def __get__(self, instance: "Container", owner: "Type[Container]") -> T: ...
184184
def __get__(
185185
self, instance: "Container | None", owner: "Type[Container]"
186186
) -> T | Self:
187-
raise NotImplementedError("Fields should only be used with Containers")
187+
raise NotImplementedError(
188+
f"Fields should only be used with Containers ({instance, owner})"
189+
)
190+
191+
def __set__(self, instance: "Container | None", value: T) -> None:
192+
raise NotImplementedError(
193+
f"Fields should only be used with Containers ({instance, value})"
194+
)
188195

189196
def __repr__(self):
190197
if self.default_factory is not None:

0 commit comments

Comments
 (0)