Skip to content

Commit 29e2a2a

Browse files
committed
Add __hash__ delegation back
In commit 0ece970, useless redefintions of the __hash__ methods were removed, as they were flagged as such by pylint. In fact, all these classes defined the __eq__ method. In that case, the __hash__ methods would have returned None. As external tools (like pyplusplus) rely on the fact that the __hash__ methods return something sensible for all types and declaration objects, we need to defined these methods. The test_hash test class has been added to make sure that the __hash__ methods are properly implemented, as this is part of the public API of pygccxml. The type_qualifiers_t class will get it's __hash__ method implemented in a separate commit, as it needs a separate test.
1 parent bda8efd commit 29e2a2a

File tree

5 files changed

+10
-0
lines changed

5 files changed

+10
-0
lines changed

pygccxml/declarations/calldef_members.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ def __eq__(self, other):
6262
and self.has_static == other.has_static \
6363
and self.has_const == other.has_const
6464

65+
__hash__ = calldef.calldef_t.__hash__
66+
6567
@property
6668
def virtuality(self):
6769
"""Describes the "virtuality" of the member (as defined by the

pygccxml/declarations/enumeration.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ def __eq__(self, other):
5151
return False
5252
return self.values == other.values
5353

54+
__hash__ = declaration.declaration_t.__hash__
55+
5456
def _get__cmp__items(self):
5557
"""implementation details"""
5658
return [self.values]

pygccxml/declarations/scopedef.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ def __eq__(self, other):
187187
return False
188188
return self.declarations[:].sort() == other.declarations[:].sort()
189189

190+
__hash__ = declaration.declaration_t.__hash__
191+
190192
def _get_declarations_impl(self):
191193
raise NotImplementedError()
192194

pygccxml/declarations/typedef.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ def __eq__(self, other):
3333
return False
3434
return self.decl_type == other.decl_type
3535

36+
__hash__ = declaration.declaration_t.__hash__
37+
3638
@property
3739
def decl_type(self):
3840
"""reference to the original :class:`decl_type <type_t>`"""

pygccxml/declarations/variable.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ def __eq__(self, other):
4545
and self.value == other.value \
4646
and self.bits == other.bits
4747

48+
__hash__ = declaration.declaration_t.__hash__
49+
4850
@property
4951
def decl_type(self):
5052
"""reference to the variable :class:`decl_type <type_t>`"""

0 commit comments

Comments
 (0)