Skip to content

Commit 4541a6e

Browse files
authored
Merge pull request #1877 from volatilityfoundation/issues/issue1874
Convert ObjectInfo form NamedTuple to Dataclass to attempt to work better with pypy3
2 parents 7536e9d + 2a2f27a commit 4541a6e

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

volatility3/framework/interfaces/objects.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
import collections
88
import collections.abc
99
import contextlib
10+
import dataclasses
1011
import logging
11-
from typing import Any, Dict, List, Mapping, NamedTuple, Optional
12+
from typing import Any, Dict, List, Mapping, Optional
1213

1314
from volatility3.framework import constants, interfaces
1415

@@ -52,7 +53,8 @@ def __eq__(self, other):
5253
return dict(self) == dict(other)
5354

5455

55-
class ObjectInformation(NamedTuple):
56+
@dataclasses.dataclass
57+
class ObjectInformation:
5658
"""Contains common information useful/pertinent only to an individual
5759
object (like an instance)
5860
@@ -71,12 +73,12 @@ class ObjectInformation(NamedTuple):
7173
size: Optional[int] = None
7274

7375
def __getitem__(self, key):
74-
if key in self._fields:
76+
if key in self:
7577
return getattr(self, key)
76-
raise KeyError(f"NamedTuple does not have a key {key}")
78+
raise KeyError(f"No {key} present in ObjectInformation")
7779

7880
def __contains__(self, key):
79-
return key in self._fields
81+
return key in [field.name for field in dataclasses.fields(self)]
8082

8183

8284
class ObjectInterface(metaclass=abc.ABCMeta):

0 commit comments

Comments
 (0)