Message314710
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. |
|
Date |
User |
Action |
Args |
2018-03-30 20:07:43 | levkivskyi | set | recipients:
+ levkivskyi, eric.smith, Ricyteach |
2018-03-30 20:07:43 | levkivskyi | set | messageid: <1522440463.47.0.467229070634.issue33188@psf.upfronthosting.co.za> |
2018-03-30 20:07:43 | levkivskyi | link | issue33188 messages |
2018-03-30 20:07:43 | levkivskyi | create | |
|