Simplified DeclarativeFieldsMetaclass.__new__() a bit.

This commit is contained in:
Vitaliy Yelnik 2020-11-02 11:46:56 +02:00 committed by GitHub
parent 42f3fafdfa
commit d1791539a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 7 deletions

View File

@ -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)