
from __future__ import absolute_import

import mongoengine
import six


def mongodb_to_python_types(value):
    if isinstance(value, mongoengine.base.datastructures.BaseDict):
        value = dict(value)

    if isinstance(value, mongoengine.base.datastructures.BaseList):
        value = list(value)

    if isinstance(value, dict):
        value = {k: mongodb_to_python_types(v) for k, v in six.iteritems(value)}

    if isinstance(value, list):
        value = [mongodb_to_python_types(v) for v in value]

    return value


from __future__ import absolute_import

import mongoengine
import six


def mongodb_to_python_types(value):
    # Convert MongoDB BaseDict and BaseList types to python dict and list types.
    if isinstance(value, mongoengine.base.datastructures.BaseDict):
        value = dict(value)
    elif isinstance(value, mongoengine.base.datastructures.BaseList):
        value = list(value)

    # Recursively traverse the dict and list to convert values.
    if isinstance(value, dict):
        value = {k: mongodb_to_python_types(v) for k, v in six.iteritems(value)}
    elif isinstance(value, list):
        value = [mongodb_to_python_types(v) for v in value]

    return value

Use if-elif instead of multiple if statements to check types
Use if-elif instead of multiple if statements to check types

Use if-elif instead of multiple if statements to check types when converting from MongoDB BaseDict and BaseList to python dict and list types. Once the value is converted, use another if-elif block to recursively evaluate and convert the values of dict and list.

  
  from __future__ import absolute_import
  
  import mongoengine
  import six
  
  
  def mongodb_to_python_types(value):
+     # Convert MongoDB BaseDict and BaseList types to python dict and list types.
      if isinstance(value, mongoengine.base.datastructures.BaseDict):
          value = dict(value)
- 
-     if isinstance(value, mongoengine.base.datastructures.BaseList):
+     elif isinstance(value, mongoengine.base.datastructures.BaseList):
          value = list(value)
  
+     # Recursively traverse the dict and list to convert values.
      if isinstance(value, dict):
          value = {k: mongodb_to_python_types(v) for k, v in six.iteritems(value)}
- 
-     if isinstance(value, list):
+     elif isinstance(value, list):
          value = [mongodb_to_python_types(v) for v in value]
  
      return value
  
Use if-elif instead of multiple if statements to check types
## Code Before:

from __future__ import absolute_import

import mongoengine
import six


def mongodb_to_python_types(value):
    if isinstance(value, mongoengine.base.datastructures.BaseDict):
        value = dict(value)

    if isinstance(value, mongoengine.base.datastructures.BaseList):
        value = list(value)

    if isinstance(value, dict):
        value = {k: mongodb_to_python_types(v) for k, v in six.iteritems(value)}

    if isinstance(value, list):
        value = [mongodb_to_python_types(v) for v in value]

    return value

## Instruction:
Use if-elif instead of multiple if statements to check types
## Code After:

from __future__ import absolute_import

import mongoengine
import six


def mongodb_to_python_types(value):
    # Convert MongoDB BaseDict and BaseList types to python dict and list types.
    if isinstance(value, mongoengine.base.datastructures.BaseDict):
        value = dict(value)
    elif isinstance(value, mongoengine.base.datastructures.BaseList):
        value = list(value)

    # Recursively traverse the dict and list to convert values.
    if isinstance(value, dict):
        value = {k: mongodb_to_python_types(v) for k, v in six.iteritems(value)}
    elif isinstance(value, list):
        value = [mongodb_to_python_types(v) for v in value]

    return value
