add docs, provide check if Config is a class, ignore dynamic bases for mypy

This commit is contained in:
collerek
2021-07-25 12:11:50 +02:00
parent 5dcbe8f0e5
commit 3528d6effa
4 changed files with 63 additions and 2 deletions

View File

@ -1,3 +1,4 @@
import inspect
from typing import (
Any,
Dict,
@ -552,12 +553,20 @@ class ModelMetaclass(pydantic.main.ModelMetaclass):
:param attrs: class namespace
:type attrs: Dict
"""
DefaultConfig = get_pydantic_base_orm_config()
if "Config" in attrs:
class Config(attrs["Config"], get_pydantic_base_orm_config()):
ProvidedConfig = attrs["Config"]
if not inspect.isclass(ProvidedConfig):
raise ModelDefinitionError(
f"Config provided for class {name} has to be a class."
)
class Config(ProvidedConfig, DefaultConfig): # type: ignore
pass
attrs["Config"] = Config
else:
attrs["Config"] = get_pydantic_base_orm_config()
attrs["Config"] = DefaultConfig
attrs["__name__"] = name
attrs, model_fields = extract_annotations_and_default_vals(attrs)