| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.
|
Sorry, something went wrong.
|
I signed! |
Sorry, something went wrong.
|
CLAs look good, thanks! |
Sorry, something went wrong.
|
I was a bit confused by what is needed, but this example clarifies for me: >>> class A(object):
... def __init__(self, val):
... self.val = val
... def __repr__(self):
... return 'A({!r})'.format(self.val)
... def __eq__(self, other):
... if not isinstance(other, A):
... return NotImplemented
... return other.val == self.val
... def __ne__(self, other):
... if not isinstance(other, A):
... return NotImplemented
... return other.val != self.val
...
>>> a1 = A(10)
>>> a2 = A(11)
>>> a3 = A(11)
>>> a1 == a2
False
>>> a1 == a3
False
>>> a2 == a3
True
>>> set([a1, a2, a3])
set([A(10), A(11), A(11)]) |
Sorry, something went wrong.
| self.fields = fields | ||
|
|
||
| def __eq__(self, other): | ||
| def __key(self): |
| self.field_type.lower(), | ||
| self.mode, | ||
| self.description, | ||
| self.fields) |
Sorry, something went wrong.
| self.mode = mode | ||
| self.description = description | ||
| self.fields = fields | ||
| self.fields = None if(fields is None) else tuple(fields) |
|
@dhermes @tseaver i modified the default arg for fields to be (). The question is what to do with how this resource is represented. Should I use () there too? This is what I did, so if you would rather have me use [] I can change that. FYI: this broke a few tests and I'm wondering if it will break any of the actual api calls. |
Sorry, something went wrong.
| info['description'] = field.description | ||
| if field.fields is not None: | ||
| info['fields'] = _build_schema_resource(field.fields) | ||
| info['fields'] = tuple(_build_schema_resource(field.fields)) |
| """ | ||
| if 'fields' not in info: | ||
| return None | ||
| return () |
| def __hash__(self): | ||
| return hash(self._key()) | ||
|
|
||
| def __repr__(self): |
|
Hmm looks like I broke some tests in circleci, let me go fix that |
Sorry, something went wrong.
|
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that they're okay with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate. |
Sorry, something went wrong.
|
@azymnis We (@jonparrott, @lukesneeringer and I) just had a discussion about this and determined SchemaField should be immutable in order to be hashable. Rather than put the burden on you, I have sent a commit into this PR to make the class immutable. |
Sorry, something went wrong.
There was a problem hiding this comment.
One style nitpick.
Sorry, something went wrong.
| 'schema': {'fields': [ | ||
| {'name': 'full_name', 'type': 'STRING', 'mode': 'REQUIRED'}, | ||
| {'name': 'age', 'type': 'INTEGER', 'mode': 'REQUIRED'}, | ||
| {'name': |
| self._fields, | ||
| ) | ||
|
|
||
| def __eq__(self, other): |
|
@dhermes makes sense, thanks for the update |
Sorry, something went wrong.
|
Thank you all! |
Sorry, something went wrong.
* Add a __hash__ implementation to SchemaField * Modify default list of subfields to be the empty tuple * Making SchemaField immutable. * Adding SchemaField.__ne__.
* Add a __hash__ implementation to SchemaField * Modify default list of subfields to be the empty tuple * Making SchemaField immutable. * Adding SchemaField.__ne__.
* Add a __hash__ implementation to SchemaField * Modify default list of subfields to be the empty tuple * Making SchemaField immutable. * Adding SchemaField.__ne__.
| Back | FazBrowse Home | New Git URL |
Problem: I need to compare a new schema with an existing table schema. Easiest way would be to use set comparison operators. However this is not possible with SchemaField because there is no implementation of __hash__.
Solution: Add a simple implementation of __hash__ using tuple keys. This is not the most efficient implementation of a hashcode but should probably be ok for most purposes.