#28873: More of dict.setdefault
------------------------------------------+------------------------
Reporter: Дилян Палаузов | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.11
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------+------------------------
{{{
diff --git a/django/db/models/fields/__init__.py
b/django/db/models/fields/__init__.py
--- a/django/db/models/fields/__init__.py
+++ b/django/db/models/fields/__init__.py
@@ -1645,7 +1645,7 @@ class EmailField(CharField):
def __init__(self, *args, **kwargs):
# max_length=254 to be compliant with RFCs 3696 and 5321
- kwargs['max_length'] = kwargs.get('max_length', 254)
+ kwargs.setdefault('max_length', 254)
super().__init__(*args, **kwargs)
def deconstruct(self):
@@ -1671,7 +1671,7 @@ class FilePathField(Field):
recursive=False, allow_files=True, allow_folders=False,
**kwargs):
self.path, self.match, self.recursive = path, match, recursive
self.allow_files, self.allow_folders = allow_files, allow_folders
- kwargs['max_length'] = kwargs.get('max_length', 100)
+ kwargs.setdefault('max_length', 100)
super().__init__(verbose_name, name, **kwargs)
def check(self, **kwargs):
@@ -2251,7 +2251,7 @@ class URLField(CharField):
description = _("URL")
def __init__(self, verbose_name=None, name=None, **kwargs):
- kwargs['max_length'] = kwargs.get('max_length', 200)
+ kwargs.setdefault('max_length', 200)
super().__init__(verbose_name, name, **kwargs)
def deconstruct(self):
diff --git a/django/db/models/fields/files.py
b/django/db/models/fields/files.py
--- a/django/db/models/fields/files.py
+++ b/django/db/models/fields/files.py
@@ -226,7 +226,7 @@ class FileField(Field):
self.storage = storage or default_storage
self.upload_to = upload_to
- kwargs['max_length'] = kwargs.get('max_length', 100)
+ kwargs.setdefault('max_length', 100)
super().__init__(verbose_name, name, **kwargs)
def check(self, **kwargs):
diff --git a/django/db/models/fields/related.py
b/django/db/models/fields/related.py
--- a/django/db/models/fields/related.py
+++ b/django/db/models/fields/related.py
@@ -809,7 +809,7 @@ class ForeignKey(ForeignObject):
on_delete=on_delete,
)
- kwargs['db_index'] = kwargs.get('db_index', True)
+ kwargs.setdefault('db_index', True)
super().__init__(to, on_delete, from_fields=['self'],
to_fields=[to_field], **kwargs)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28873>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/057.7b8cacd09ac5e8f136795dccba63c4af%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.