Simplified DeclarativeFieldsMetaclass.__new__() a bit.
This commit is contained in:
parent
42f3fafdfa
commit
d1791539a7
|
@ -22,13 +22,11 @@ __all__ = ('BaseForm', 'Form')
|
||||||
class DeclarativeFieldsMetaclass(MediaDefiningClass):
|
class DeclarativeFieldsMetaclass(MediaDefiningClass):
|
||||||
"""Collect Fields declared on the base classes."""
|
"""Collect Fields declared on the base classes."""
|
||||||
def __new__(mcs, name, bases, attrs):
|
def __new__(mcs, name, bases, attrs):
|
||||||
# Collect fields from current class.
|
# Collect fields from current class and remove them from attrs.
|
||||||
current_fields = []
|
attrs['declared_fields'] = {
|
||||||
for key, value in list(attrs.items()):
|
key: attrs.pop(key) for key, value in list(attrs.items())
|
||||||
if isinstance(value, Field):
|
if isinstance(value, Field)
|
||||||
current_fields.append((key, value))
|
}
|
||||||
attrs.pop(key)
|
|
||||||
attrs['declared_fields'] = dict(current_fields)
|
|
||||||
|
|
||||||
new_class = super().__new__(mcs, name, bases, attrs)
|
new_class = super().__new__(mcs, name, bases, attrs)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue