From d1791539a7d86739cd44c909fa8239cae7f85874 Mon Sep 17 00:00:00 2001 From: Vitaliy Yelnik Date: Mon, 2 Nov 2020 11:46:56 +0200 Subject: [PATCH] Simplified DeclarativeFieldsMetaclass.__new__() a bit. --- django/forms/forms.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/django/forms/forms.py b/django/forms/forms.py index 81c59dea33..14f5dea4cd 100644 --- a/django/forms/forms.py +++ b/django/forms/forms.py @@ -22,13 +22,11 @@ __all__ = ('BaseForm', 'Form') class DeclarativeFieldsMetaclass(MediaDefiningClass): """Collect Fields declared on the base classes.""" def __new__(mcs, name, bases, attrs): - # Collect fields from current class. - current_fields = [] - for key, value in list(attrs.items()): - if isinstance(value, Field): - current_fields.append((key, value)) - attrs.pop(key) - attrs['declared_fields'] = dict(current_fields) + # Collect fields from current class and remove them from attrs. + attrs['declared_fields'] = { + key: attrs.pop(key) for key, value in list(attrs.items()) + if isinstance(value, Field) + } new_class = super().__new__(mcs, name, bases, attrs)