Reverted "Fixed #27818 -- Replaced try/except/pass with contextlib.suppress()."

This reverts commit 550cb3a365
because try/except performs better.
This commit is contained in:
Tim Graham 2017-09-07 08:16:21 -04:00 committed by GitHub
parent 8b2515a450
commit 6e4c6281db
66 changed files with 351 additions and 207 deletions

View file

@ -3,7 +3,6 @@ import inspect
import warnings
from bisect import bisect
from collections import OrderedDict, defaultdict
from contextlib import suppress
from django.apps import apps
from django.conf import settings
@ -269,8 +268,10 @@ class Options:
# is a cached property, and all the models haven't been loaded yet, so
# we need to make sure we don't cache a string reference.
if field.is_relation and hasattr(field.remote_field, 'model') and field.remote_field.model:
with suppress(AttributeError):
try:
field.remote_field.model._meta._expire_cache(forward=False)
except AttributeError:
pass
self._expire_cache()
else:
self._expire_cache(reverse=False)
@ -518,8 +519,10 @@ class Options:
# Due to the way Django's internals work, get_field() should also
# be able to fetch a field by attname. In the case of a concrete
# field with relation, includes the *_id name too
with suppress(AttributeError):
try:
res[field.attname] = field
except AttributeError:
pass
return res
@cached_property
@ -531,8 +534,10 @@ class Options:
# Due to the way Django's internals work, get_field() should also
# be able to fetch a field by attname. In the case of a concrete
# field with relation, includes the *_id name too
with suppress(AttributeError):
try:
res[field.attname] = field
except AttributeError:
pass
return res
def get_field(self, field_name):
@ -749,10 +754,12 @@ class Options:
# Creates a cache key composed of all arguments
cache_key = (forward, reverse, include_parents, include_hidden, topmost_call)
with suppress(KeyError):
try:
# In order to avoid list manipulation. Always return a shallow copy
# of the results.
return self._get_fields_cache[cache_key]
except KeyError:
pass
fields = []
# Recursively call _get_fields() on each parent, with the same