Ivan Levkivskyi <levkivs...@gmail.com> added the comment:

This is not a bug but an explicit design decision. Generic classes are _static_ 
typing concept and therefore are not supposed to work freely with _dynamic_ 
class creation. During discussion of PEP 560 it was decided that there should 
be at least one way to dynamically create generic classes, `types.new_class` 
was chosen for this, see 
https://www.python.org/dev/peps/pep-0560/#dynamic-class-creation-and-types-resolve-bases

Also the exception message is quite clear about this. Unfortunately, PEPs 560 
and 557 were discussed in parallel so not every possible interactions where 
thought out. But is it critical for dataclasses to call `type`? I believe there 
should be no other differences with `types.new_class`. I would say the latter 
is even better than `type` because it correctly treats `__prepare__` on the 
metaclass IIRC. So I would propose to switch from `type()` to 
`types.new_class()` for dynamic creation of dataclasses.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue33188>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to