New submission from Rick Teachey <[email protected]>:
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 <[email protected]>
<https://bugs.python.org/issue33188>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com