Swap ObjectInformation from namedtuple to dataclass

This commit is contained in:
Mike Auty
2025-09-15 20:00:09 +01:00
parent 78e05f9c8f
commit 1a1f3be633
+6 -4
View File
@@ -7,6 +7,7 @@ import abc
import collections
import collections.abc
import contextlib
import dataclasses
import logging
from typing import Any, Dict, List, Mapping, NamedTuple, Optional
@@ -52,7 +53,8 @@ class ReadOnlyMapping(collections.abc.Mapping):
return dict(self) == dict(other)
class ObjectInformation(NamedTuple):
@dataclasses.dataclass
class ObjectInformation:
"""Contains common information useful/pertinent only to an individual
object (like an instance)
@@ -71,12 +73,12 @@ class ObjectInformation(NamedTuple):
size: Optional[int] = None
def __getitem__(self, key):
if key in self._fields:
if key in self:
return getattr(self, key)
raise KeyError(f"NamedTuple does not have a key {key}")
raise KeyError(f"No {key} present in ObjectInformation")
def __contains__(self, key):
return key in self._fields
return key in [field.name for field in dataclasses.fields(self)]
class ObjectInterface(metaclass=abc.ABCMeta):