The Lennart hypothesis is true: the metaclass is indeed the culprit. No need to guess, just look at the sources : the metaclass DeclarativeFieldsMetaclass is currently located on line 53 of this file and adds the base_fields and possibly media attributes based on what attributes the class has at creation time. On line 329 ff you will see:
class Form(BaseForm): "A collection of Fields, plus their associated data."
This implies some fragility when creating a new class with a type base - the supplied black magic may or may not pass! A firmer approach is to use the EmployeeForm type, which will pick up any metaclass that may be involved, i.e.:
return type(EmployeeForm)('EmployeeForm', (forms.Form, ), EmployeeForm.__dict__)
(no need to copy this __dict__ , by the way). The difference is subtle, but important: instead of using the direct form type 3-args, we use the 1-arg form to get the type (that is, the Metaclass) of the form class, and then call this metaclass in 3-args.
Black magic is valid, but then, the lack of frameworks that use such a use of the โfantasy metaclassโ exclusively for semantic sugar "& c: you are in clover if you want to do exactly what the framework supports, but leaving this support may even require a little compensate for the magic (which to some extent explains why often I prefer to use a light transparent setting such as werkzeug rather than a framework that imposes magic on me like Rails or Django do: my skill about deep black magic does NOT mean that I am glad that I should use it in simple production code ... but, this is another discussion ;-).
source share