Skip to content

Commit

Permalink
Workaround hashing issue with unset label
Browse files Browse the repository at this point in the history
  • Loading branch information
p-snft committed Dec 19, 2023
1 parent 51397ff commit 12b665a
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/oemof/network/network/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def __lt__(self, other):
def __hash__(self):
return hash(self.label)


def __str__(self):
return str(self.label)

Expand All @@ -76,11 +77,18 @@ def label(self):
attribute holds the actual object passed as a parameter. Otherwise
`node.label` is a synonym for `str(node)`.
"""
return (
self._label
if self._label is not None
else "<{} #0x{:x}>".format(type(self).__name__, id(self))
)
try:
return (
self._label
if self._label is not None
else self._id_label
)
except AttributeError:
return hash(self._id_label)

@property
def _id_label(self):
return "<{} #0x{:x}>".format(type(self).__name__, id(self))

@label.setter
def label(self, label):
Expand Down

0 comments on commit 12b665a

Please sign in to comment.