This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author levkivskyi
Recipients Ricyteach, eric.smith, levkivskyi
Date 2018-03-30.20:07:43
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1522440463.47.0.467229070634.issue33188@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2018-03-30 20:07:43levkivskyisetrecipients: + levkivskyi, eric.smith, Ricyteach
2018-03-30 20:07:43levkivskyisetmessageid: <1522440463.47.0.467229070634.issue33188@psf.upfronthosting.co.za>
2018-03-30 20:07:43levkivskyilinkissue33188 messages
2018-03-30 20:07:43levkivskyicreate