summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMads Jensen <mje@inducks.org>2017-03-27 19:12:27 +0200
committerTim Graham <timograham@gmail.com>2017-03-27 13:12:27 -0400
commited0cbc8d8b314e3b4a0305d0be3cf366d8ee4a74 (patch)
treecafdedf0f6d8601f5749ee9350b5e4acdf2b8e59
parent6585ebebaaa58aeef45210a3119dbaa322f8baca (diff)
Refs #23919 -- Removed some Python 2 compatibility code and comments.
-rw-r--r--django/contrib/admin/checks.py4
-rw-r--r--django/contrib/admindocs/views.py7
-rw-r--r--django/db/models/query.py14
3 files changed, 6 insertions, 19 deletions
diff --git a/django/contrib/admin/checks.py b/django/contrib/admin/checks.py
index 07d3341569..b8d34ce9c2 100644
--- a/django/contrib/admin/checks.py
+++ b/django/contrib/admin/checks.py
@@ -662,9 +662,7 @@ class ModelAdminChecks(BaseModelAdminChecks):
elif not isinstance(obj.list_display_links, (list, tuple)):
return must_be('a list, a tuple, or None', option='list_display_links', obj=obj, id='admin.E110')
# Check only if ModelAdmin.get_list_display() isn't overridden.
- elif obj.get_list_display.__code__ is ModelAdmin.get_list_display.__code__:
- # Use obj.get_list_display.__func__ is ModelAdmin.get_list_display
- # when dropping PY2.
+ elif obj.get_list_display.__func__ is ModelAdmin.get_list_display:
return list(chain(*[
self._check_list_display_links_item(obj, field_name, "list_display_links[%d]" % index)
for index, field_name in enumerate(obj.list_display_links)
diff --git a/django/contrib/admindocs/views.py b/django/contrib/admindocs/views.py
index 25263ec129..2b96ee3e8f 100644
--- a/django/contrib/admindocs/views.py
+++ b/django/contrib/admindocs/views.py
@@ -168,13 +168,6 @@ class ViewDetailView(BaseAdminDocsView):
# the module and class.
mod, klass = get_mod_func(mod)
return getattr(getattr(import_module(mod), klass), func)
- except AttributeError:
- # PY2 generates incorrect paths for views that are methods,
- # e.g. 'mymodule.views.ViewContainer.my_view' will be
- # listed as 'mymodule.views.my_view' because the class name
- # can't be detected. This causes an AttributeError when
- # trying to resolve the view.
- return None
def get_context_data(self, **kwargs):
view = self.kwargs['view']
diff --git a/django/db/models/query.py b/django/db/models/query.py
index 8ee1b34117..67c1f83d13 100644
--- a/django/db/models/query.py
+++ b/django/db/models/query.py
@@ -319,10 +319,9 @@ class QuerySet:
if self.query.distinct_fields:
raise NotImplementedError("aggregate() + distinct(fields) not implemented.")
for arg in args:
- # The default_alias property may raise a TypeError, so we use
- # a try/except construct rather than hasattr in order to remain
- # consistent between PY2 and PY3 (hasattr would swallow
- # the TypeError on PY2).
+ # The default_alias property raises TypeError if default_alias
+ # can't be set automatically or AttributeError if it isn't an
+ # attribute.
try:
arg.default_alias
except (AttributeError, TypeError):
@@ -880,16 +879,13 @@ class QuerySet:
"""
annotations = OrderedDict() # To preserve ordering of args
for arg in args:
- # The default_alias property may raise a TypeError, so we use
- # a try/except construct rather than hasattr in order to remain
- # consistent between PY2 and PY3 (hasattr would swallow
- # the TypeError on PY2).
+ # The default_alias property may raise a TypeError.
try:
if arg.default_alias in kwargs:
raise ValueError("The named annotation '%s' conflicts with the "
"default name for another annotation."
% arg.default_alias)
- except (AttributeError, TypeError):
+ except TypeError:
raise TypeError("Complex annotations require an alias")
annotations[arg.default_alias] = arg
annotations.update(kwargs)