Skip to content

Commit

Permalink
Removed unnecessary arguments in .get method calls
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrjakimiak committed May 13, 2015
1 parent f61c4f4 commit 4157c50
Show file tree
Hide file tree
Showing 39 changed files with 78 additions and 79 deletions.
11 changes: 5 additions & 6 deletions django/contrib/admin/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def value(self):
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):
"""
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion django/contrib/admin/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def get_field_queryset(self, db, db_field, request):
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 != ():
Expand Down
2 changes: 1 addition & 1 deletion django/contrib/auth/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class Meta:

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

Expand Down
2 changes: 1 addition & 1 deletion django/contrib/auth/management/commands/createsuperuser.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def execute(self, *args, **options):
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
Expand Down
4 changes: 2 additions & 2 deletions django/contrib/flatpages/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def clean_url(self):
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:
Expand Down
10 changes: 5 additions & 5 deletions django/contrib/gis/db/models/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def area(self, tolerance=0.05, **kwargs):
# 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,
Expand Down Expand Up @@ -403,7 +403,7 @@ def transform(self, srid=4326, **kwargs):
"""
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()
Expand Down Expand Up @@ -534,7 +534,7 @@ def _spatial_attribute(self, att, settings, field_name=None, model_att=None):
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:
Expand Down Expand Up @@ -563,7 +563,7 @@ def _spatial_attribute(self, att, settings, field_name=None, model_att=None):
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
Expand All @@ -583,7 +583,7 @@ def _distance_attribute(self, func, geom=None, tolerance=0.05, spheroid=False, *
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
Expand Down
2 changes: 1 addition & 1 deletion django/contrib/gis/feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def add_georss_element(self, handler, item, w3c_geo=False):
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
Expand Down
2 changes: 1 addition & 1 deletion django/contrib/gis/gdal/geomtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(self, type_input):
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):
Expand Down
2 changes: 1 addition & 1 deletion django/contrib/gis/geoip/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def __init__(self, path=None, cache=0, country=None, city=None):

# 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):
Expand Down
2 changes: 1 addition & 1 deletion django/contrib/gis/geoip/libgeoip.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
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/
Expand Down
2 changes: 1 addition & 1 deletion django/contrib/gis/geos/linestring.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def __init__(self, *args, **kwargs):
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.
Expand Down
2 changes: 1 addition & 1 deletion django/contrib/postgres/forms/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def render(self, name, value, attrs=None):
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]
Expand Down
2 changes: 1 addition & 1 deletion django/contrib/sessions/backends/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def cache_key(self):

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.
Expand Down
2 changes: 1 addition & 1 deletion django/contrib/sessions/backends/cached_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def cache_key(self):

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.
Expand Down
2 changes: 1 addition & 1 deletion django/contrib/sessions/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def __init__(self):
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):
Expand Down
8 changes: 4 additions & 4 deletions django/contrib/sitemaps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ def _urls(self, page, protocol, domain):
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
Expand All @@ -123,7 +123,7 @@ def _urls(self, page, protocol, domain):
'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)
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion django/contrib/staticfiles/finders.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def find_in_app(self, app, path):
"""
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):
Expand Down
4 changes: 2 additions & 2 deletions django/contrib/staticfiles/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def load_manifest(self):
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)" %
Expand Down Expand Up @@ -341,7 +341,7 @@ def __setitem__(self, key, value):
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
Expand Down
2 changes: 1 addition & 1 deletion django/core/cache/backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def __init__(self, params):

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):
"""
Expand Down
2 changes: 1 addition & 1 deletion django/core/cache/backends/memcached.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self, server, params, library, value_not_found_exception):
self.LibraryValueNotFoundException = value_not_found_exception

self._lib = library
self._options = params.get('OPTIONS', None)
self._options = params.get('OPTIONS')

@property
def _cache(self):
Expand Down
2 changes: 1 addition & 1 deletion django/core/management/commands/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def handle(self, *app_labels, **options):
else:
app_configs = None

tags = options.get('tags', None)
tags = options.get('tags')
if tags:
try:
invalid_tag = next(
Expand Down
4 changes: 2 additions & 2 deletions django/core/management/commands/makemigrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def handle(self, *app_labels, **options):
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
Expand Down Expand Up @@ -165,7 +165,7 @@ def write_migration_files(self, changes):
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")
Expand Down
4 changes: 2 additions & 2 deletions django/core/serializers/xml_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
14 changes: 7 additions & 7 deletions django/db/migrations/autodetector.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ def generate_created_proxies(self):
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),
Expand Down Expand Up @@ -695,7 +695,7 @@ def generate_deleted_models(self):
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
Expand All @@ -714,7 +714,7 @@ def generate_deleted_proxies(self):
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(
Expand Down Expand Up @@ -980,12 +980,12 @@ def generate_altered_order_with_respect_to(self):
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,
Expand All @@ -997,7 +997,7 @@ def generate_altered_order_with_respect_to(self):
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,
)
Expand Down
8 changes: 4 additions & 4 deletions django/db/models/fields/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1739,7 +1739,7 @@ def deconstruct(self):
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

Expand Down Expand Up @@ -1955,7 +1955,7 @@ def deconstruct(self):
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

Expand Down Expand Up @@ -2099,7 +2099,7 @@ def __init__(self, *args, **kwargs):

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
Expand Down Expand Up @@ -2288,7 +2288,7 @@ def __init__(self, verbose_name=None, name=None, **kwargs):

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

Expand Down
Loading

0 comments on commit 4157c50

Please sign in to comment.