Refs #23919 -- Removed some Python 2 compatibility code and comments.
This commit is contained in:
parent
6585ebebaa
commit
ed0cbc8d8b
|
@ -662,9 +662,7 @@ class ModelAdminChecks(BaseModelAdminChecks):
|
||||||
elif not isinstance(obj.list_display_links, (list, tuple)):
|
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')
|
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.
|
# Check only if ModelAdmin.get_list_display() isn't overridden.
|
||||||
elif obj.get_list_display.__code__ is ModelAdmin.get_list_display.__code__:
|
elif obj.get_list_display.__func__ is ModelAdmin.get_list_display:
|
||||||
# Use obj.get_list_display.__func__ is ModelAdmin.get_list_display
|
|
||||||
# when dropping PY2.
|
|
||||||
return list(chain(*[
|
return list(chain(*[
|
||||||
self._check_list_display_links_item(obj, field_name, "list_display_links[%d]" % index)
|
self._check_list_display_links_item(obj, field_name, "list_display_links[%d]" % index)
|
||||||
for index, field_name in enumerate(obj.list_display_links)
|
for index, field_name in enumerate(obj.list_display_links)
|
||||||
|
|
|
@ -168,13 +168,6 @@ class ViewDetailView(BaseAdminDocsView):
|
||||||
# the module and class.
|
# the module and class.
|
||||||
mod, klass = get_mod_func(mod)
|
mod, klass = get_mod_func(mod)
|
||||||
return getattr(getattr(import_module(mod), klass), func)
|
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):
|
def get_context_data(self, **kwargs):
|
||||||
view = self.kwargs['view']
|
view = self.kwargs['view']
|
||||||
|
|
|
@ -319,10 +319,9 @@ class QuerySet:
|
||||||
if self.query.distinct_fields:
|
if self.query.distinct_fields:
|
||||||
raise NotImplementedError("aggregate() + distinct(fields) not implemented.")
|
raise NotImplementedError("aggregate() + distinct(fields) not implemented.")
|
||||||
for arg in args:
|
for arg in args:
|
||||||
# The default_alias property may raise a TypeError, so we use
|
# The default_alias property raises TypeError if default_alias
|
||||||
# a try/except construct rather than hasattr in order to remain
|
# can't be set automatically or AttributeError if it isn't an
|
||||||
# consistent between PY2 and PY3 (hasattr would swallow
|
# attribute.
|
||||||
# the TypeError on PY2).
|
|
||||||
try:
|
try:
|
||||||
arg.default_alias
|
arg.default_alias
|
||||||
except (AttributeError, TypeError):
|
except (AttributeError, TypeError):
|
||||||
|
@ -880,16 +879,13 @@ class QuerySet:
|
||||||
"""
|
"""
|
||||||
annotations = OrderedDict() # To preserve ordering of args
|
annotations = OrderedDict() # To preserve ordering of args
|
||||||
for arg in args:
|
for arg in args:
|
||||||
# The default_alias property may raise a TypeError, so we use
|
# The default_alias property may raise a TypeError.
|
||||||
# a try/except construct rather than hasattr in order to remain
|
|
||||||
# consistent between PY2 and PY3 (hasattr would swallow
|
|
||||||
# the TypeError on PY2).
|
|
||||||
try:
|
try:
|
||||||
if arg.default_alias in kwargs:
|
if arg.default_alias in kwargs:
|
||||||
raise ValueError("The named annotation '%s' conflicts with the "
|
raise ValueError("The named annotation '%s' conflicts with the "
|
||||||
"default name for another annotation."
|
"default name for another annotation."
|
||||||
% arg.default_alias)
|
% arg.default_alias)
|
||||||
except (AttributeError, TypeError):
|
except TypeError:
|
||||||
raise TypeError("Complex annotations require an alias")
|
raise TypeError("Complex annotations require an alias")
|
||||||
annotations[arg.default_alias] = arg
|
annotations[arg.default_alias] = arg
|
||||||
annotations.update(kwargs)
|
annotations.update(kwargs)
|
||||||
|
|
Loading…
Reference in New Issue