Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ApiRoute: Provide a hash implementation, too. #261

Merged
merged 2 commits into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions stone/ir/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,20 @@ def __ge__(self, other):
return self._compare(self, other) >= 0
def __ne__(self, other):
return self._compare(self, other) != 0
def __hash__(self):
return hash((
self.name,
self.version,
self._ast_node,
self.deprecated,
self.raw_doc,
self.doc,
self.arg_data_type,
self.result_data_type,
self.error_data_type,
id(self.attrs)
))


class DeprecationInfo(object):

Expand Down
9 changes: 9 additions & 0 deletions test/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,5 +505,14 @@ def test_no_preserve_aliases_from_api(self):
field = dependent_struct.fields[0]
self.assertIsInstance(field.data_type, String)

def test_route_hashing(self):
route = ApiRoute('test/route', 1, None)
same_route = ApiRoute("test/route", 1, None)
diff_version = ApiRoute("test/route", 2, None)
diff_route = ApiRoute("test/route_2", 1, None)
self.assertEqual(hash(route), hash(same_route))
self.assertNotEqual(hash(route), hash(diff_version))
self.assertNotEqual(hash(route), hash(diff_route))

if __name__ == '__main__':
unittest.main()