Skip to content

Commit 89486c6

Browse files
Manuel Leonhardtpriv-kweihmann
authored andcommitted
Speedup getting attributes
This change avoids using the inspect module which is considerably slow. Instead members are iterated using dir and getattr.
1 parent 2dc2975 commit 89486c6

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

oelint_parser/cls_item.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import textwrap
22
import re
3-
import inspect
43

54
from oelint_parser.const_func import KNOWN_FUNCS
65
from oelint_parser.const_vars import get_known_machines
@@ -214,11 +213,17 @@ def GetAttributes(self):
214213
Returns:
215214
dict -- all public attributes and their values
216215
"""
216+
T = type(self)
217217
res = {}
218-
classes = inspect.getmembers(self, inspect.isclass)
219-
for cls in classes:
220-
for x in inspect.getmembers(cls[1], lambda o: isinstance(o, property)):
221-
res[x[0]] = x[1].fget(self)
218+
for _ in dir(self):
219+
try:
220+
attr = getattr(T, _)
221+
except AttributeError:
222+
continue # Skip dunder attributes, i.e. private attributes
223+
else:
224+
if isinstance(attr, property):
225+
res[_] = getattr(self, _)
226+
222227
return res
223228

224229
def __repr__(self):

0 commit comments

Comments
 (0)