Skip to content

Commit 880160e

Browse files
authored
feat(error): implement __sizeof__ for fabric error (#20)
1 parent 1459a55 commit 880160e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/core/ydata/core/error/fabric_error.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22
import json
33
from typing import Optional
4+
from sys import getsizeof
45

56

67
def _camelcased(value: str) -> str:
@@ -43,5 +44,16 @@ def __str__(self) -> str:
4344
def __repr__(self) -> str:
4445
return self.__str__()
4546

47+
def __sizeof__(self) -> int:
48+
context_size = getsizeof(self.context) if self.context else 0
49+
http_code_size = getsizeof(str(self.http_code)) if self.http_code else 0
50+
return_value_size = getsizeof(str(self.return_value)) if self.return_value else 0
51+
52+
return context_size \
53+
+ getsizeof(self.description) \
54+
+ http_code_size \
55+
+ getsizeof(self.name) \
56+
+ return_value_size
57+
4658
def json(self):
4759
return json.dumps(self, default=lambda o: {_camelcased(k): v for k, v in dict(o).items()}, ensure_ascii=False)

0 commit comments

Comments
 (0)