clean conflicts and some cleaning

This commit is contained in:
collerek
2020-08-19 19:23:04 +07:00
6 changed files with 7 additions and 26 deletions

View File

@ -171,9 +171,7 @@ class FakePydantic(pydantic.BaseModel, metaclass=ModelMetaclass):
exclude_defaults: bool = False,
exclude_none: bool = False,
nested: bool = False
) -> 'DictStrAny': # noqa: A003
print('callin super', self.__class__)
print('to exclude', self._exclude_related_names_not_required(nested))
) -> 'DictStrAny': # noqa: A003'
dict_instance = super().dict(include=include,
exclude=self._exclude_related_names_not_required(nested),
by_alias=by_alias,
@ -181,9 +179,7 @@ class FakePydantic(pydantic.BaseModel, metaclass=ModelMetaclass):
exclude_unset=exclude_unset,
exclude_defaults=exclude_defaults,
exclude_none=exclude_none)
print('after super')
for field in self._extract_related_names():
print(self.__class__, field, nested)
nested_model = getattr(self, field)
if self.Meta.model_fields[field].virtual and nested:
@ -191,13 +187,9 @@ class FakePydantic(pydantic.BaseModel, metaclass=ModelMetaclass):
if isinstance(nested_model, list) and not isinstance(
nested_model, ormar.Model
):
print('nested list')
dict_instance[field] = [x.dict(nested=True) for x in nested_model]
else:
print('instance')
if nested_model is not None:
dict_instance[field] = nested_model.dict(nested=True)
elif nested_model is not None:
dict_instance[field] = nested_model.dict(nested=True)
return dict_instance
def from_dict(self, value_dict: Dict) -> None:

View File

@ -113,11 +113,9 @@ def populate_pydantic_default_values(attrs: Dict) -> Dict:
type_.name = field
def_value = type_.default_value()
curr_def_value = attrs.get(field, 'NONE')
print(field, curr_def_value, 'def val', type_.nullable)
if curr_def_value == 'NONE' and isinstance(def_value, FieldInfo):
attrs[field] = def_value
elif curr_def_value == 'NONE' and type_.nullable:
print(field, 'defsults tp none')
attrs[field] = FieldInfo(default=None)
return attrs
@ -147,8 +145,6 @@ class ModelMetaclass(pydantic.main.ModelMetaclass):
annotations = attrs.get("__annotations__") or new_model.__annotations__
attrs["__annotations__"]= annotations
attrs = populate_pydantic_default_values(attrs)
print(attrs)
tablename = name.lower() + "s"
new_model.Meta.tablename = new_model.Meta.tablename or tablename
@ -182,8 +178,6 @@ class ModelMetaclass(pydantic.main.ModelMetaclass):
)
new_model.Meta.model_fields = model_fields
print(attrs, 'before super')
print(new_model.Meta.__dict__)
new_model = super().__new__( # type: ignore
mcs, name, bases, attrs
)