diff options
| author | Vitaliy Yelnik <velnik@gmail.com> | 2020-11-02 11:46:56 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-02 10:46:56 +0100 |
| commit | d1791539a7d86739cd44c909fa8239cae7f85874 (patch) | |
| tree | a3d9ff27a4f31ee006a3709b2dd0f02cb45deef0 /django/forms | |
| parent | 42f3fafdfab01f6b04b817c45140e8309eecf84c (diff) | |
Simplified DeclarativeFieldsMetaclass.__new__() a bit.
Diffstat (limited to 'django/forms')
| -rw-r--r-- | django/forms/forms.py | 12 |
1 files 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) |
