[New-bugs-announce] [issue33188] dataclass MRO entry resolution for type variable metaclasses: TypeError

Rick Teachey report at bugs.python.org
Fri Mar 30 14:03:43 EDT 2018


New submission from Rick Teachey <ricky at teachey.org>:

I'm getting the following error at when attempting to create a new `dataclass` with any base class that is supplied a type variable:

    TypeError: type() doesn't support MRO entry resolution; use types.new_class()

In principle, it seems like this shouldn't cause any problems, since this works as expected:

    @dataclass
    class MyClass(Generic[MyTypeVar]):
        pass

The problem seems to be the call to `type` in `make_dataclass` for instantiating the class object, since `type` doesn't support type variables. If I replace the `dataclass` line that produces the error with the following code block, it seems to work:

    try:
        cls = type(cls_name, bases, namespace)
    except TypeError:
        cls = types.new_class(cls_name, bases, namespace)

I haven't tested, but it might be possible to just remove the call to `type` altogether.

I've attached a file demonstrating the issue.

----------
components: Library (Lib)
files: dataclass_metaclass_issue.py
messages: 314703
nosy: Ricyteach, eric.smith
priority: normal
severity: normal
status: open
title: dataclass MRO entry resolution for type variable metaclasses: TypeError
type: behavior
versions: Python 3.7, Python 3.8
Added file: https://bugs.python.org/file47508/dataclass_metaclass_issue.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33188>
_______________________________________


More information about the New-bugs-announce mailing list