Skip to content

Commit

Permalink
fix(model): Hide deprecated attributes from dir()
Browse files Browse the repository at this point in the history
This helps a bit with the issue described in #434.
  • Loading branch information
Wuestengecko committed Jul 11, 2024
1 parent 216ca02 commit 983ef59
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions capellambse/model/common/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,25 @@ def __eq__(self, other: object) -> bool:
return NotImplemented
return self._element is other._element

def __dir__(self) -> list[str]:
badacc = (accessors.DeprecatedAccessor,)
cls = type(self)
attrs: list[str] = []
for i in super().__dir__():
try:
acc = getattr(cls, i)
except Exception:
continue
if isinstance(acc, badacc):
continue
try:
if getattr(acc, "__deprecated__", None):
continue
except Exception:
continue
attrs.append(i)
return attrs

@deprecated("Hashing of elements is deprecated, use the '.uuid' instead")
def __hash__(self):
return hash(self._element)
Expand Down

0 comments on commit 983ef59

Please sign in to comment.