diff --git a/src/ctapipe/core/container.py b/src/ctapipe/core/container.py index 7c27034140c..2f37193b116 100644 --- a/src/ctapipe/core/container.py +++ b/src/ctapipe/core/container.py @@ -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, @@ -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 @@ -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: