fix some code smells
This commit is contained in:
@ -234,10 +234,9 @@ def get_pydantic_example_repr(type_: Any) -> Any:
|
||||
"""
|
||||
if issubclass(type_, (numbers.Number, decimal.Decimal)):
|
||||
return 0
|
||||
elif issubclass(type_, pydantic.BaseModel):
|
||||
if issubclass(type_, pydantic.BaseModel):
|
||||
return generate_pydantic_example(pydantic_model=type_)
|
||||
else:
|
||||
return "string"
|
||||
return "string"
|
||||
|
||||
|
||||
def overwrite_example_and_description(
|
||||
|
||||
@ -252,12 +252,9 @@ class NewBaseModel(pydantic.BaseModel, ModelTableProxy, metaclass=ModelMetaclass
|
||||
for field_name in self.extract_through_names():
|
||||
through_tmp_dict[field_name] = kwargs.pop(field_name, None)
|
||||
|
||||
if self.Meta.extra == Extra.ignore:
|
||||
kwargs = {
|
||||
k: v
|
||||
for k, v in kwargs.items()
|
||||
if k in model_fields or k in pydantic_fields
|
||||
}
|
||||
kwargs = self._remove_extra_parameters_if_they_should_be_ignored(
|
||||
kwargs=kwargs, model_fields=model_fields, pydantic_fields=pydantic_fields
|
||||
)
|
||||
try:
|
||||
new_kwargs: Dict[str, Any] = {
|
||||
k: self._convert_to_bytes(
|
||||
@ -283,6 +280,29 @@ class NewBaseModel(pydantic.BaseModel, ModelTableProxy, metaclass=ModelMetaclass
|
||||
|
||||
return new_kwargs, through_tmp_dict
|
||||
|
||||
def _remove_extra_parameters_if_they_should_be_ignored(
|
||||
self, kwargs: Dict, model_fields: Dict, pydantic_fields: Set
|
||||
) -> Dict:
|
||||
"""
|
||||
Removes the extra fields from kwargs if they should be ignored.
|
||||
|
||||
:param kwargs: passed arguments
|
||||
:type kwargs: Dict
|
||||
:param model_fields: dictionary of model fields
|
||||
:type model_fields: Dict
|
||||
:param pydantic_fields: set of pydantic fields names
|
||||
:type pydantic_fields: Set
|
||||
:return: dict without extra fields
|
||||
:rtype: Dict
|
||||
"""
|
||||
if self.Meta.extra == Extra.ignore:
|
||||
kwargs = {
|
||||
k: v
|
||||
for k, v in kwargs.items()
|
||||
if k in model_fields or k in pydantic_fields
|
||||
}
|
||||
return kwargs
|
||||
|
||||
def _initialize_internal_attributes(self) -> None:
|
||||
"""
|
||||
Initializes internal attributes during __init__()
|
||||
|
||||
Reference in New Issue
Block a user