Skip to content

create_model not support generics model #3945

@hot123s

Description

@hot123s

Checks

  • I added a descriptive title to this issue
  • I have searched (google, github) for similar issues and couldn't find anything
  • I have read and followed the docs and still think this is a bug

Bug

from typing import Generic, TypeVar

from pydantic import Field, create_model
from pydantic.generics import GenericModel

T = TypeVar("T")


class TestGenericModel(GenericModel):
    pass


AAModel = create_model("AAModel", __base__=(TestGenericModel, Generic[T]), aa=(int, Field(0)))

AAModel[int](aa=1)

output

Traceback (most recent call last):
  File "test.py", line 13, in <module>
    AAModel = create_model("AAModel", __base__=(TestGenericModel, Generic[T]), aa=(int, Field(0)))
  File "pydantic/main.py", line 972, in pydantic.main.create_model
TypeError: type() doesn't support MRO entry resolution; use types.new_class()

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug V1Bug related to Pydantic V1.X

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions