Commit 70843703 authored by Qijiang Fan's avatar Qijiang Fan Committed by Commit Bot

Make module.Field hashable.

For Python3 compatibility.

Converting [module.StructField] into set requires StructField to be
hashable, but module.StructField has __eq__ defined only not __hash__.

$ python3 ./mojo/public/tools/bindings/mojom_bindings_generator.py generate $(pwd)/mojo/public/mojom/base/time.mojom --bytecode_path . -d $(pwd)
Traceback (most recent call last):
<stacktrace partially trimmed>
  File "/ssd2/chromium/src/mojo/public/tools/bindings/generators/mojom_cpp_generator.py", line 961, in <genexpr>
    for param_count in param_counts)
  File "/ssd2/chromium/src/mojo/public/tools/bindings/generators/mojom_cpp_generator.py", line 205, in __init__
    self._params = set(params)
TypeError: unhashable type: 'StructField'

Bug: 941669
Change-Id: I1ca8f67d86754cbad668a47a6f0ddd513e5ce896
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2277687
Commit-Queue: Qijiang Fan <fqj@chromium.org>
Auto-Submit: Qijiang Fan <fqj@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Cr-Commit-Position: refs/heads/master@{#785294}
parent f33a5405
...@@ -363,6 +363,9 @@ class Field(object): ...@@ -363,6 +363,9 @@ class Field(object):
self.attributes) == (rhs.mojom_name, rhs.kind, rhs.ordinal, self.attributes) == (rhs.mojom_name, rhs.kind, rhs.ordinal,
rhs.default, rhs.attributes)) rhs.default, rhs.attributes))
def __hash__(self):
return hash((self.mojom_name, self.kind, self.ordinal, self.default))
class StructField(Field): class StructField(Field):
pass pass
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment