Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/ctapipe/core/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def __init__(
unit: None = None,
ucd: Any = None,
dtype: None = None,
type: None = None,
type: Type[T] | None = None,
ndim: None = None,
allow_none: bool = False,
max_length: None = None,
Expand Down Expand Up @@ -170,7 +170,7 @@ def __init__(
if default_factory is not None and default is not None:
raise ValueError("Must only provide one of default or default_factory")

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

def __set__(self, instance: "Container | None", value: T) -> None:
raise NotImplementedError(
f"Fields should only be used with Containers ({instance, value})"
)

def __repr__(self):
if self.default_factory is not None:
Expand Down
Loading