Merge remote-tracking branch 'origin/master' into 5.2.x

This commit is contained in:
William Cheng
2021-04-28 17:48:21 +08:00
1666 changed files with 42781 additions and 17405 deletions

View File

@@ -1508,13 +1508,19 @@ def model_to_dict(model_instance, serialize=True):
# exist in attribute_map
attr = model_instance.attribute_map.get(attr, attr)
if isinstance(value, list):
if not value or isinstance(value[0], PRIMITIVE_TYPES):
# empty list or primitive types
result[attr] = value
elif isinstance(value[0], ModelSimple):
result[attr] = [x.value for x in value]
else:
result[attr] = [model_to_dict(x, serialize=serialize) for x in value]
if not value:
# empty list or None
result[attr] = value
else:
res = []
for v in value:
if isinstance(v, PRIMITIVE_TYPES) or v is None:
res.append(v)
elif isinstance(v, ModelSimple):
res.append(v.value)
else:
res.append(model_to_dict(v, serialize=serialize))
result[attr] = res
elif isinstance(value, dict):
result[attr] = dict(map(
lambda item: (item[0],
@@ -1574,11 +1580,16 @@ def get_valid_classes_phrase(input_classes):
def convert_js_args_to_python_args(fn):
from functools import wraps
@wraps(fn)
def wrapped_init(self, *args, **kwargs):
def wrapped_init(_self, *args, **kwargs):
"""
An attribute named `self` received from the api will conflicts with the reserved `self`
parameter of a class method. During generation, `self` attributes are mapped
to `_self` in models. Here, we name `_self` instead of `self` to avoid conflicts.
"""
spec_property_naming = kwargs.get('_spec_property_naming', False)
if spec_property_naming:
kwargs = change_keys_js_to_python(kwargs, self.__class__)
return fn(self, *args, **kwargs)
kwargs = change_keys_js_to_python(kwargs, _self.__class__)
return fn(_self, *args, **kwargs)
return wrapped_init