Merge pull request #1874 from erdenezul/reduce-cycle-complexity

reduce cycle complexity using logic map
This commit is contained in:
erdenezul 2018-09-04 20:52:26 +08:00 committed by GitHub
commit 00bf6ac258
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -214,17 +214,20 @@ def update(_doc_cls=None, **update):
if parts[0] in UPDATE_OPERATORS: if parts[0] in UPDATE_OPERATORS:
op = parts.pop(0) op = parts.pop(0)
# Convert Pythonic names to Mongo equivalents # Convert Pythonic names to Mongo equivalents
if op in ('push_all', 'pull_all'): operator_map = {
op = op.replace('_all', 'All') 'push_all': 'pushAll',
elif op == 'dec': 'pull_all': 'pullAll',
'dec': 'inc',
'add_to_set': 'addToSet',
'set_on_insert': 'setOnInsert'
}
if op == 'dec':
# Support decrement by flipping a positive value's sign # Support decrement by flipping a positive value's sign
# and using 'inc' # and using 'inc'
op = 'inc'
value = -value value = -value
elif op == 'add_to_set': # If the operator doesn't found from operator map, the op value
op = 'addToSet' # will stay unchanged
elif op == 'set_on_insert': op = operator_map.get(op, op)
op = 'setOnInsert'
match = None match = None
if parts[-1] in COMPARISON_OPERATORS: if parts[-1] in COMPARISON_OPERATORS: