From 4157c502a5202798d0f73645181cb82aa71d34d9 Mon Sep 17 00:00:00 2001 From: Piotr Jakimiak Date: Wed, 13 May 2015 20:51:18 +0200 Subject: [PATCH] Removed unnecessary arguments in .get method calls --- django/contrib/admin/filters.py | 11 +++++----- django/contrib/admin/options.py | 2 +- django/contrib/auth/forms.py | 2 +- .../management/commands/createsuperuser.py | 2 +- django/contrib/flatpages/forms.py | 4 ++-- django/contrib/gis/db/models/query.py | 10 ++++----- django/contrib/gis/feeds.py | 2 +- django/contrib/gis/gdal/geomtype.py | 2 +- django/contrib/gis/geoip/base.py | 2 +- django/contrib/gis/geoip/libgeoip.py | 2 +- django/contrib/gis/geos/linestring.py | 2 +- django/contrib/postgres/forms/array.py | 2 +- django/contrib/sessions/backends/cache.py | 2 +- django/contrib/sessions/backends/cached_db.py | 2 +- django/contrib/sessions/middleware.py | 2 +- django/contrib/sitemaps/__init__.py | 8 +++---- django/contrib/staticfiles/finders.py | 2 +- django/contrib/staticfiles/storage.py | 4 ++-- django/core/cache/backends/base.py | 2 +- django/core/cache/backends/memcached.py | 2 +- django/core/management/commands/check.py | 2 +- .../management/commands/makemigrations.py | 4 ++-- django/core/serializers/xml_serializer.py | 4 ++-- django/db/migrations/autodetector.py | 14 ++++++------ django/db/models/fields/__init__.py | 8 +++---- django/db/models/fields/files.py | 2 +- django/db/models/query.py | 2 +- django/forms/models.py | 2 +- django/forms/widgets.py | 22 +++++++++---------- django/http/request.py | 2 +- django/middleware/cache.py | 4 ++-- django/middleware/clickjacking.py | 2 +- django/template/base.py | 4 ++-- django/template/defaulttags.py | 2 +- django/test/client.py | 2 +- django/utils/cache.py | 4 ++-- django/views/decorators/clickjacking.py | 4 ++-- django/views/generic/detail.py | 4 ++-- django/views/i18n.py | 2 +- 39 files changed, 78 insertions(+), 79 deletions(-) diff --git a/django/contrib/admin/filters.py b/django/contrib/admin/filters.py index 80ba2eebc6..a5704812cf 100644 --- a/django/contrib/admin/filters.py +++ b/django/contrib/admin/filters.py @@ -85,7 +85,7 @@ class SimpleListFilter(ListFilter): query string for this filter, if any. If the value wasn't provided then returns None. """ - return self.used_parameters.get(self.parameter_name, None) + return self.used_parameters.get(self.parameter_name) def lookups(self, request, model_admin): """ @@ -220,8 +220,8 @@ class BooleanFieldListFilter(FieldListFilter): def __init__(self, field, request, params, model, model_admin, field_path): self.lookup_kwarg = '%s__exact' % field_path self.lookup_kwarg2 = '%s__isnull' % field_path - self.lookup_val = request.GET.get(self.lookup_kwarg, None) - self.lookup_val2 = request.GET.get(self.lookup_kwarg2, None) + self.lookup_val = request.GET.get(self.lookup_kwarg) + self.lookup_val2 = request.GET.get(self.lookup_kwarg2) super(BooleanFieldListFilter, self).__init__(field, request, params, model, model_admin, field_path) @@ -350,9 +350,8 @@ class AllValuesFieldListFilter(FieldListFilter): def __init__(self, field, request, params, model, model_admin, field_path): self.lookup_kwarg = field_path self.lookup_kwarg_isnull = '%s__isnull' % field_path - self.lookup_val = request.GET.get(self.lookup_kwarg, None) - self.lookup_val_isnull = request.GET.get(self.lookup_kwarg_isnull, - None) + self.lookup_val = request.GET.get(self.lookup_kwarg) + self.lookup_val_isnull = request.GET.get(self.lookup_kwarg_isnull) parent_model, reverse_path = reverse_field_path(model, field_path) # Obey parent ModelAdmin queryset when deciding which options to show if model == parent_model: diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index 5f150aca2b..ece061490f 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -200,7 +200,7 @@ class BaseModelAdmin(six.with_metaclass(forms.MediaDefiningClass)): ordering. Otherwise don't specify the queryset, let the field decide (returns None in that case). """ - related_admin = self.admin_site._registry.get(db_field.remote_field.model, None) + related_admin = self.admin_site._registry.get(db_field.remote_field.model) if related_admin is not None: ordering = related_admin.get_ordering(request) if ordering is not None and ordering != (): diff --git a/django/contrib/auth/forms.py b/django/contrib/auth/forms.py index 84fc757e26..daf46e4a81 100644 --- a/django/contrib/auth/forms.py +++ b/django/contrib/auth/forms.py @@ -106,7 +106,7 @@ class UserChangeForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(UserChangeForm, self).__init__(*args, **kwargs) - f = self.fields.get('user_permissions', None) + f = self.fields.get('user_permissions') if f is not None: f.queryset = f.queryset.select_related('content_type') diff --git a/django/contrib/auth/management/commands/createsuperuser.py b/django/contrib/auth/management/commands/createsuperuser.py index c1251b32d6..7d374b863d 100644 --- a/django/contrib/auth/management/commands/createsuperuser.py +++ b/django/contrib/auth/management/commands/createsuperuser.py @@ -50,7 +50,7 @@ class Command(BaseCommand): return super(Command, self).execute(*args, **options) def handle(self, *args, **options): - username = options.get(self.UserModel.USERNAME_FIELD, None) + username = options.get(self.UserModel.USERNAME_FIELD) database = options.get('database') # If not provided, create the user with an unusable password diff --git a/django/contrib/flatpages/forms.py b/django/contrib/flatpages/forms.py index 6e7448c397..b990fa36de 100644 --- a/django/contrib/flatpages/forms.py +++ b/django/contrib/flatpages/forms.py @@ -35,8 +35,8 @@ class FlatpageForm(forms.ModelForm): return url def clean(self): - url = self.cleaned_data.get('url', None) - sites = self.cleaned_data.get('sites', None) + url = self.cleaned_data.get('url') + sites = self.cleaned_data.get('sites') same_url = FlatPage.objects.filter(url=url) if self.instance.pk: diff --git a/django/contrib/gis/db/models/query.py b/django/contrib/gis/db/models/query.py index c2a46399d2..4fe9969b0d 100644 --- a/django/contrib/gis/db/models/query.py +++ b/django/contrib/gis/db/models/query.py @@ -32,7 +32,7 @@ class GeoQuerySet(QuerySet): # Performing setup here rather than in `_spatial_attribute` so that # we can get the units for `AreaField`. procedure_args, geo_field = self._spatial_setup( - 'area', field_name=kwargs.get('field_name', None)) + 'area', field_name=kwargs.get('field_name')) s = {'procedure_args': procedure_args, 'geo_field': geo_field, 'setup': False, @@ -403,7 +403,7 @@ class GeoQuerySet(QuerySet): """ if not isinstance(srid, six.integer_types): raise TypeError('An integer SRID must be provided.') - field_name = kwargs.get('field_name', None) + field_name = kwargs.get('field_name') self._spatial_setup('transform', field_name=field_name) self.query.add_context('transformed_srid', srid) return self._clone() @@ -534,7 +534,7 @@ class GeoQuerySet(QuerySet): if settings.get('setup', True): default_args, geo_field = self._spatial_setup( att, desc=settings['desc'], field_name=field_name, - geo_field_type=settings.get('geo_field_type', None)) + geo_field_type=settings.get('geo_field_type')) for k, v in six.iteritems(default_args): settings['procedure_args'].setdefault(k, v) else: @@ -563,7 +563,7 @@ class GeoQuerySet(QuerySet): fmt = '%%(function)s(%s)' % settings['procedure_fmt'] # If the result of this function needs to be converted. - if settings.get('select_field', False): + if settings.get('select_field'): select_field = settings['select_field'] if connection.ops.oracle: select_field.empty_strings_allowed = False @@ -583,7 +583,7 @@ class GeoQuerySet(QuerySet): DRY routine for GeoQuerySet distance attribute routines. """ # Setting up the distance procedure arguments. - procedure_args, geo_field = self._spatial_setup(func, field_name=kwargs.get('field_name', None)) + procedure_args, geo_field = self._spatial_setup(func, field_name=kwargs.get('field_name')) # If geodetic defaulting distance attribute to meters (Oracle and # PostGIS spherical distances return meters). Otherwise, use the diff --git a/django/contrib/gis/feeds.py b/django/contrib/gis/feeds.py index fc66beec45..555602fa9f 100644 --- a/django/contrib/gis/feeds.py +++ b/django/contrib/gis/feeds.py @@ -36,7 +36,7 @@ class GeoFeedMixin(object): This routine adds a GeoRSS XML element using the given item and handler. """ # Getting the Geometry object. - geom = item.get('geometry', None) + geom = item.get('geometry') if geom is not None: if isinstance(geom, (list, tuple)): # Special case if a tuple/list was passed in. The tuple may be diff --git a/django/contrib/gis/gdal/geomtype.py b/django/contrib/gis/gdal/geomtype.py index 0c672e4227..c1e1934886 100644 --- a/django/contrib/gis/gdal/geomtype.py +++ b/django/contrib/gis/gdal/geomtype.py @@ -37,7 +37,7 @@ class OGRGeomType(object): type_input = type_input.lower() if type_input == 'geometry': type_input = 'unknown' - num = self._str_types.get(type_input, None) + num = self._str_types.get(type_input) if num is None: raise GDALException('Invalid OGR String Type "%s"' % type_input) elif isinstance(type_input, int): diff --git a/django/contrib/gis/geoip/base.py b/django/contrib/gis/geoip/base.py index 0b160ffea3..39a651f727 100644 --- a/django/contrib/gis/geoip/base.py +++ b/django/contrib/gis/geoip/base.py @@ -89,7 +89,7 @@ class GeoIP(object): # Getting the GeoIP data path. if not path: - path = GEOIP_SETTINGS.get('GEOIP_PATH', None) + path = GEOIP_SETTINGS.get('GEOIP_PATH') if not path: raise GeoIPException('GeoIP path must be provided via parameter or the GEOIP_PATH setting.') if not isinstance(path, six.string_types): diff --git a/django/contrib/gis/geoip/libgeoip.py b/django/contrib/gis/geoip/libgeoip.py index a6023ff229..c5f5d24b82 100644 --- a/django/contrib/gis/geoip/libgeoip.py +++ b/django/contrib/gis/geoip/libgeoip.py @@ -8,7 +8,7 @@ from django.conf import settings GEOIP_SETTINGS = {key: getattr(settings, key) for key in ('GEOIP_PATH', 'GEOIP_LIBRARY_PATH', 'GEOIP_COUNTRY', 'GEOIP_CITY') if hasattr(settings, key)} -lib_path = GEOIP_SETTINGS.get('GEOIP_LIBRARY_PATH', None) +lib_path = GEOIP_SETTINGS.get('GEOIP_LIBRARY_PATH') # The shared library for the GeoIP C API. May be downloaded # from http://www.maxmind.com/download/geoip/api/c/ diff --git a/django/contrib/gis/geos/linestring.py b/django/contrib/gis/geos/linestring.py index 8e191c4b04..f1c26af72e 100644 --- a/django/contrib/gis/geos/linestring.py +++ b/django/contrib/gis/geos/linestring.py @@ -72,7 +72,7 @@ class LineString(ProjectInterpolateMixin, GEOSGeometry): cs[i] = coords[i] # If SRID was passed in with the keyword arguments - srid = kwargs.get('srid', None) + srid = kwargs.get('srid') # Calling the base geometry initialization with the returned pointer # from the function. diff --git a/django/contrib/postgres/forms/array.py b/django/contrib/postgres/forms/array.py index 01c4d53527..1e8b44f975 100644 --- a/django/contrib/postgres/forms/array.py +++ b/django/contrib/postgres/forms/array.py @@ -112,7 +112,7 @@ class SplitArrayWidget(forms.Widget): value = value or [] output = [] final_attrs = self.build_attrs(attrs) - id_ = final_attrs.get('id', None) + id_ = final_attrs.get('id') for i in range(max(len(value), self.size)): try: widget_value = value[i] diff --git a/django/contrib/sessions/backends/cache.py b/django/contrib/sessions/backends/cache.py index 38b6112f51..9ee8351930 100644 --- a/django/contrib/sessions/backends/cache.py +++ b/django/contrib/sessions/backends/cache.py @@ -20,7 +20,7 @@ class SessionStore(SessionBase): def load(self): try: - session_data = self._cache.get(self.cache_key, None) + session_data = self._cache.get(self.cache_key) except Exception: # Some backends (e.g. memcache) raise an exception on invalid # cache keys. If this happens, reset the session. See #17810. diff --git a/django/contrib/sessions/backends/cached_db.py b/django/contrib/sessions/backends/cached_db.py index 23e0a74bbf..848913b51e 100644 --- a/django/contrib/sessions/backends/cached_db.py +++ b/django/contrib/sessions/backends/cached_db.py @@ -29,7 +29,7 @@ class SessionStore(DBStore): def load(self): try: - data = self._cache.get(self.cache_key, None) + data = self._cache.get(self.cache_key) except Exception: # Some backends (e.g. memcache) raise an exception on invalid # cache keys. If this happens, reset the session. See #17810. diff --git a/django/contrib/sessions/middleware.py b/django/contrib/sessions/middleware.py index 69ca669033..dc22b6605d 100644 --- a/django/contrib/sessions/middleware.py +++ b/django/contrib/sessions/middleware.py @@ -12,7 +12,7 @@ class SessionMiddleware(object): self.SessionStore = engine.SessionStore def process_request(self, request): - session_key = request.COOKIES.get(settings.SESSION_COOKIE_NAME, None) + session_key = request.COOKIES.get(settings.SESSION_COOKIE_NAME) request.session = self.SessionStore(session_key) def process_response(self, request, response): diff --git a/django/contrib/sitemaps/__init__.py b/django/contrib/sitemaps/__init__.py index 930279bf96..0fc646d36a 100644 --- a/django/contrib/sitemaps/__init__.py +++ b/django/contrib/sitemaps/__init__.py @@ -112,8 +112,8 @@ class Sitemap(object): all_items_lastmod = True # track if all items have a lastmod for item in self.paginator.page(page).object_list: loc = "%s://%s%s" % (protocol, domain, self.__get('location', item)) - priority = self.__get('priority', item, None) - lastmod = self.__get('lastmod', item, None) + priority = self.__get('priority', item) + lastmod = self.__get('lastmod', item) if all_items_lastmod: all_items_lastmod = lastmod is not None if (all_items_lastmod and @@ -123,7 +123,7 @@ class Sitemap(object): 'item': item, 'location': loc, 'lastmod': lastmod, - 'changefreq': self.__get('changefreq', item, None), + 'changefreq': self.__get('changefreq', item), 'priority': str(priority if priority is not None else ''), } urls.append(url_info) @@ -138,7 +138,7 @@ class GenericSitemap(Sitemap): def __init__(self, info_dict, priority=None, changefreq=None): self.queryset = info_dict['queryset'] - self.date_field = info_dict.get('date_field', None) + self.date_field = info_dict.get('date_field') self.priority = priority self.changefreq = changefreq diff --git a/django/contrib/staticfiles/finders.py b/django/contrib/staticfiles/finders.py index 7c775e7f89..81a919bf04 100644 --- a/django/contrib/staticfiles/finders.py +++ b/django/contrib/staticfiles/finders.py @@ -168,7 +168,7 @@ class AppDirectoriesFinder(BaseFinder): """ Find a requested static file in an app's static locations. """ - storage = self.storages.get(app, None) + storage = self.storages.get(app) if storage: # only try to find a file if the source dir actually exists if storage.exists(path): diff --git a/django/contrib/staticfiles/storage.py b/django/contrib/staticfiles/storage.py index 6a0a5407dd..b3c53b7232 100644 --- a/django/contrib/staticfiles/storage.py +++ b/django/contrib/staticfiles/storage.py @@ -308,7 +308,7 @@ class ManifestFilesMixin(HashedFilesMixin): except ValueError: pass else: - version = stored.get('version', None) + version = stored.get('version') if version == '1.0': return stored.get('paths', OrderedDict()) raise ValueError("Couldn't load manifest '%s' (version %s)" % @@ -341,7 +341,7 @@ class _MappingCache(object): self.cache.set(key, value) def __getitem__(self, key): - value = self.cache.get(key, None) + value = self.cache.get(key) if value is None: raise KeyError("Couldn't find a file name '%s'" % key) return value diff --git a/django/core/cache/backends/base.py b/django/core/cache/backends/base.py index 26113aaa31..0ffd47bc2a 100644 --- a/django/core/cache/backends/base.py +++ b/django/core/cache/backends/base.py @@ -74,7 +74,7 @@ class BaseCache(object): self.key_prefix = params.get('KEY_PREFIX', '') self.version = params.get('VERSION', 1) - self.key_func = get_key_func(params.get('KEY_FUNCTION', None)) + self.key_func = get_key_func(params.get('KEY_FUNCTION')) def get_backend_timeout(self, timeout=DEFAULT_TIMEOUT): """ diff --git a/django/core/cache/backends/memcached.py b/django/core/cache/backends/memcached.py index af68885641..fdd12a1e16 100644 --- a/django/core/cache/backends/memcached.py +++ b/django/core/cache/backends/memcached.py @@ -24,7 +24,7 @@ class BaseMemcachedCache(BaseCache): self.LibraryValueNotFoundException = value_not_found_exception self._lib = library - self._options = params.get('OPTIONS', None) + self._options = params.get('OPTIONS') @property def _cache(self): diff --git a/django/core/management/commands/check.py b/django/core/management/commands/check.py index 818700e4ed..f50d234f8c 100644 --- a/django/core/management/commands/check.py +++ b/django/core/management/commands/check.py @@ -32,7 +32,7 @@ class Command(BaseCommand): else: app_configs = None - tags = options.get('tags', None) + tags = options.get('tags') if tags: try: invalid_tag = next( diff --git a/django/core/management/commands/makemigrations.py b/django/core/management/commands/makemigrations.py index 2fe220b622..4cd36f3c8a 100644 --- a/django/core/management/commands/makemigrations.py +++ b/django/core/management/commands/makemigrations.py @@ -43,7 +43,7 @@ class Command(BaseCommand): self.dry_run = options.get('dry_run', False) self.merge = options.get('merge', False) self.empty = options.get('empty', False) - self.migration_name = options.get('name', None) + self.migration_name = options.get('name') self.exit_code = options.get('exit_code', False) # Make sure the app they asked for exists @@ -165,7 +165,7 @@ class Command(BaseCommand): if not self.dry_run: # Write the migrations file to the disk. migrations_directory = os.path.dirname(writer.path) - if not directory_created.get(app_label, False): + if not directory_created.get(app_label): if not os.path.isdir(migrations_directory): os.mkdir(migrations_directory) init_path = os.path.join(migrations_directory, "__init__.py") diff --git a/django/core/serializers/xml_serializer.py b/django/core/serializers/xml_serializer.py index 0a301cb946..e8415230d6 100644 --- a/django/core/serializers/xml_serializer.py +++ b/django/core/serializers/xml_serializer.py @@ -23,8 +23,8 @@ class Serializer(base.Serializer): """ def indent(self, level): - if self.options.get('indent', None) is not None: - self.xml.ignorableWhitespace('\n' + ' ' * self.options.get('indent', None) * level) + if self.options.get('indent') is not None: + self.xml.ignorableWhitespace('\n' + ' ' * self.options.get('indent') * level) def start_serialization(self): """ diff --git a/django/db/migrations/autodetector.py b/django/db/migrations/autodetector.py index a73985d724..ad6aeda380 100644 --- a/django/db/migrations/autodetector.py +++ b/django/db/migrations/autodetector.py @@ -591,7 +591,7 @@ class MigrationAutodetector(object): added = set(self.new_proxy_keys) - set(self.old_proxy_keys) for app_label, model_name in sorted(added): model_state = self.to_state.models[app_label, model_name] - assert model_state.options.get("proxy", False) + assert model_state.options.get("proxy") # Depend on the deletion of any possible non-proxy version of us dependencies = [ (app_label, model_name, None, False), @@ -695,7 +695,7 @@ class MigrationAutodetector(object): for name, field in sorted(related_fields.items()): dependencies.append((app_label, model_name, name, False)) # We're referenced in another field's through= - through_user = self.through_users.get((app_label, model_state.name_lower), None) + through_user = self.through_users.get((app_label, model_state.name_lower)) if through_user: dependencies.append((through_user[0], through_user[1], through_user[2], False)) # Finally, make the operation, deduping any dependencies @@ -714,7 +714,7 @@ class MigrationAutodetector(object): deleted = set(self.old_proxy_keys) - set(self.new_proxy_keys) for app_label, model_name in sorted(deleted): model_state = self.from_state.models[app_label, model_name] - assert model_state.options.get("proxy", False) + assert model_state.options.get("proxy") self.add_operation( app_label, operations.DeleteModel( @@ -980,12 +980,12 @@ class MigrationAutodetector(object): old_model_name = self.renamed_models.get((app_label, model_name), model_name) old_model_state = self.from_state.models[app_label, old_model_name] new_model_state = self.to_state.models[app_label, model_name] - if (old_model_state.options.get("order_with_respect_to", None) != - new_model_state.options.get("order_with_respect_to", None)): + if (old_model_state.options.get("order_with_respect_to") != + new_model_state.options.get("order_with_respect_to")): # Make sure it comes second if we're adding # (removal dependency is part of RemoveField) dependencies = [] - if new_model_state.options.get("order_with_respect_to", None): + if new_model_state.options.get("order_with_respect_to"): dependencies.append(( app_label, model_name, @@ -997,7 +997,7 @@ class MigrationAutodetector(object): app_label, operations.AlterOrderWithRespectTo( name=model_name, - order_with_respect_to=new_model_state.options.get('order_with_respect_to', None), + order_with_respect_to=new_model_state.options.get('order_with_respect_to'), ), dependencies=dependencies, ) diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index 98594b6127..78e74b7850 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -1739,7 +1739,7 @@ class FilePathField(Field): kwargs['allow_files'] = self.allow_files if self.allow_folders is not False: kwargs['allow_folders'] = self.allow_folders - if kwargs.get("max_length", None) == 100: + if kwargs.get("max_length") == 100: del kwargs["max_length"] return name, path, args, kwargs @@ -1955,7 +1955,7 @@ class GenericIPAddressField(Field): kwargs['unpack_ipv4'] = self.unpack_ipv4 if self.protocol != "both": kwargs['protocol'] = self.protocol - if kwargs.get("max_length", None) == 39: + if kwargs.get("max_length") == 39: del kwargs['max_length'] return name, path, args, kwargs @@ -2099,7 +2099,7 @@ class SlugField(CharField): def deconstruct(self): name, path, args, kwargs = super(SlugField, self).deconstruct() - if kwargs.get("max_length", None) == 50: + if kwargs.get("max_length") == 50: del kwargs['max_length'] if self.db_index is False: kwargs['db_index'] = False @@ -2288,7 +2288,7 @@ class URLField(CharField): def deconstruct(self): name, path, args, kwargs = super(URLField, self).deconstruct() - if kwargs.get("max_length", None) == 200: + if kwargs.get("max_length") == 200: del kwargs['max_length'] return name, path, args, kwargs diff --git a/django/db/models/fields/files.py b/django/db/models/fields/files.py index 2363088a6e..3f4c7064e4 100644 --- a/django/db/models/fields/files.py +++ b/django/db/models/fields/files.py @@ -282,7 +282,7 @@ class FileField(Field): def deconstruct(self): name, path, args, kwargs = super(FileField, self).deconstruct() - if kwargs.get("max_length", None) == 100: + if kwargs.get("max_length") == 100: del kwargs["max_length"] kwargs['upload_to'] = self.upload_to if self.storage is not default_storage: diff --git a/django/db/models/query.py b/django/db/models/query.py index 5f455b12be..050994811a 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -1216,7 +1216,7 @@ class RawQuerySet(object): model_cls = deferred_class_factory(self.model, skip) else: model_cls = self.model - fields = [self.model_fields.get(c, None) for c in self.columns] + fields = [self.model_fields.get(c) for c in self.columns] converters = compiler.get_converters([ f.get_col(f.model._meta.db_table) if f else None for f in fields ]) diff --git a/django/forms/models.py b/django/forms/models.py index 3c3f1e29ff..c5d1423376 100644 --- a/django/forms/models.py +++ b/django/forms/models.py @@ -378,7 +378,7 @@ class BaseModelForm(BaseForm): # from validation. else: form_field = self.fields[field] - field_value = self.cleaned_data.get(field, None) + field_value = self.cleaned_data.get(field) if not f.blank and not form_field.required and field_value in form_field.empty_values: exclude.append(f.name) return exclude diff --git a/django/forms/widgets.py b/django/forms/widgets.py index 24d2dc87a4..cc82c2ec79 100644 --- a/django/forms/widgets.py +++ b/django/forms/widgets.py @@ -50,7 +50,7 @@ class Media(object): self._js = [] for name in MEDIA_TYPES: - getattr(self, 'add_' + name)(media_attrs.get(name, None)) + getattr(self, 'add_' + name)(media_attrs.get(name)) def __str__(self): return self.render() @@ -228,7 +228,7 @@ class Widget(six.with_metaclass(MediaDefiningClass)): Given a dictionary of data and this widget's name, returns the value of this widget. Returns None if it's not provided. """ - return data.get(name, None) + return data.get(name) def id_for_label(self, id_): """ @@ -317,7 +317,7 @@ class MultipleHiddenInput(HiddenInput): if value is None: value = [] final_attrs = self.build_attrs(attrs, type=self.input_type, name=name) - id_ = final_attrs.get('id', None) + id_ = final_attrs.get('id') inputs = [] for i, v in enumerate(value): input_attrs = dict(value=force_text(v), **final_attrs) @@ -331,7 +331,7 @@ class MultipleHiddenInput(HiddenInput): def value_from_datadict(self, data, files, name): if isinstance(data, MultiValueDict): return data.getlist(name) - return data.get(name, None) + return data.get(name) class FileInput(Input): @@ -343,7 +343,7 @@ class FileInput(Input): def value_from_datadict(self, data, files, name): "File widgets take data from FILES, not POST" - return files.get(name, None) + return files.get(name) FILE_INPUT_CONTRADICTION = object() @@ -581,13 +581,13 @@ class NullBooleanSelect(Select): return super(NullBooleanSelect, self).render(name, value, attrs, choices) def value_from_datadict(self, data, files, name): - value = data.get(name, None) + value = data.get(name) return {'2': True, True: True, 'True': True, '3': False, 'False': False, - False: False}.get(value, None) + False: False}.get(value) class SelectMultiple(Select): @@ -607,7 +607,7 @@ class SelectMultiple(Select): def value_from_datadict(self, data, files, name): if isinstance(data, MultiValueDict): return data.getlist(name) - return data.get(name, None) + return data.get(name) @html_safe @@ -706,7 +706,7 @@ class ChoiceFieldRenderer(object): If an id was given to the field, it is applied to the