Skip to content

Commit

Permalink
chore: fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
TheKevJames committed Dec 17, 2024
1 parent e7adc9f commit 488fa82
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
11 changes: 7 additions & 4 deletions datastore/gcloud/aio/datastore/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,13 @@ def to_repr(self) -> Dict[str, Any]:
# TODO: consider refactoring to look more like Value.to_repr()
if isinstance(self.value, Array):
rep['value'] = {'arrayValue': self.value.to_repr()}
elif isinstance(self.value, Value) and isinstance(self.value.value, list):
# This is a special case where the value is type of Value, but its value is a list
rep['value'] = {'arrayValue': {'values': [Value(x).to_repr() for x in
self.value.value]}}
elif (isinstance(self.value, Value)
and isinstance(self.value.value, list)):
# This allows for a bit of syntactic sugar such that folks can pass
# in a list directly (ie. as a Value instead of as an Array, as the
# Google APIs would return it).
values = [Value(x).to_repr() for x in self.value.value]
rep['value'] = {'arrayValue': {'values': values}}
else:
rep['value'] = self.value.to_repr()
return rep
11 changes: 8 additions & 3 deletions datastore/tests/unit/filter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,14 @@ def test_repr_returns_to_repr_as_string(query_filter):
assert repr(query_filter) == str(query_filter.to_repr())

def test_in_filter_with_list_arg(self):
expected_value = {'arrayValue': {
'values': [{'excludeFromIndexes': False, 'stringValue': 'value1'},
{'excludeFromIndexes': False, 'stringValue': 'value2'}]}}
expected_value = {
'arrayValue': {
'values': [
{'excludeFromIndexes': False, 'stringValue': 'value1'},
{'excludeFromIndexes': False, 'stringValue': 'value2'},
],
},
}

prop = 'prop1'
value = ['value1', 'value2']
Expand Down

0 comments on commit 488fa82

Please sign in to comment.