Allow PYSON Expression as key for PYSON In with dict object
issue10542
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
* Allow PYSON Expression as key for PYSON In with dict object
|
||||
* Add method to format warning name with records
|
||||
* Add option to trytond-console to start a readonly transaction
|
||||
* Add support for werkzeug 2.0
|
||||
|
||||
+8
-2
@@ -485,11 +485,17 @@ class In(PYSON):
|
||||
assert obj.types().issubset({dict, list}), \
|
||||
'obj must be a dict or a list'
|
||||
if obj.types() == {dict}:
|
||||
assert isinstance(key, str), 'key must be a string'
|
||||
if isinstance(key, PYSON):
|
||||
assert key.types() == {str}, 'key must be a string'
|
||||
else:
|
||||
assert isinstance(key, str), 'key must be a string'
|
||||
else:
|
||||
assert isinstance(obj, (dict, list))
|
||||
if isinstance(obj, dict):
|
||||
assert isinstance(key, str), 'key must be a string'
|
||||
if isinstance(key, PYSON):
|
||||
assert key.types() == {str}, 'key must be a string'
|
||||
else:
|
||||
assert isinstance(key, str), 'key must be a string'
|
||||
self._key = key
|
||||
self._obj = obj
|
||||
|
||||
|
||||
@@ -461,12 +461,20 @@ class PYSONTestCase(unittest.TestCase):
|
||||
eval = pyson.PYSONEncoder().encode(pyson.In('foo', {'foo': 'bar'}))
|
||||
self.assertTrue(pyson.PYSONDecoder().decode(eval))
|
||||
|
||||
eval = pyson.PYSONEncoder().encode(pyson.In(
|
||||
pyson.Eval('test', 'foo'), {'foo': 'bar'}))
|
||||
self.assertTrue(pyson.PYSONDecoder().decode(eval))
|
||||
|
||||
eval = pyson.PYSONEncoder().encode(pyson.In('1', {1: 'bar'}))
|
||||
self.assertTrue(pyson.PYSONDecoder().decode(eval))
|
||||
|
||||
eval = pyson.PYSONEncoder().encode(pyson.In('test', {'foo': 'bar'}))
|
||||
self.assertFalse(pyson.PYSONDecoder().decode(eval))
|
||||
|
||||
eval = pyson.PYSONEncoder().encode(pyson.In(
|
||||
pyson.Eval('foo', 'test'), {'foo': 'bar'}))
|
||||
self.assertFalse(pyson.PYSONDecoder().decode(eval))
|
||||
|
||||
eval = pyson.PYSONEncoder().encode(pyson.In('1', {2: 'bar'}))
|
||||
self.assertFalse(pyson.PYSONDecoder().decode(eval))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user