replace except: pass with suppress() context manager
This commit is contained in:
parent
23694b207b
commit
341c2f98e5
5 changed files with 12 additions and 22 deletions
|
@ -1,3 +1,5 @@
|
|||
from contextlib import suppress
|
||||
|
||||
from django.apps import apps
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
@ -23,10 +25,8 @@ class LocationSlug(SerializableMixin, models.Model):
|
|||
def get_child(self):
|
||||
# todo: cache this
|
||||
for model in LOCATION_MODELS+[LocationRedirect]:
|
||||
try:
|
||||
with suppress(AttributeError):
|
||||
return getattr(self, model._meta.default_related_name)
|
||||
except AttributeError:
|
||||
pass
|
||||
return None
|
||||
|
||||
def get_slug(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue