diff options
| author | Mads Jensen <mje@inducks.org> | 2017-03-09 16:17:41 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-06-28 14:07:55 -0400 |
| commit | 550cb3a365dee4edfdd1563224d5304de2a57fda (patch) | |
| tree | fb532f38774ff7619edd2a4532c3daae1ee0ac5a /django/urls | |
| parent | 43a4835edf32c57eb74c0eb207c276734a34abcf (diff) | |
Fixed #27818 -- Replaced try/except/pass with contextlib.suppress().
Diffstat (limited to 'django/urls')
| -rw-r--r-- | django/urls/base.py | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/django/urls/base.py b/django/urls/base.py index 6dccdd2e7d..26084dbe3e 100644 --- a/django/urls/base.py +++ b/django/urls/base.py @@ -1,3 +1,4 @@ +from contextlib import suppress from threading import local from urllib.parse import urlsplit, urlunsplit @@ -53,7 +54,7 @@ def reverse(viewname, urlconf=None, args=None, kwargs=None, current_app=None): ns = path.pop() current_ns = current_path.pop() if current_path else None # Lookup the name to see if it could be an app identifier. - try: + with suppress(KeyError): app_list = resolver.app_dict[ns] # Yes! Path part matches an app in the current Resolver. if current_ns and current_ns in app_list: @@ -64,8 +65,6 @@ def reverse(viewname, urlconf=None, args=None, kwargs=None, current_app=None): # The name isn't shared by one of the instances (i.e., # the default) so pick the first instance as the default. ns = app_list[0] - except KeyError: - pass if ns != current_ns: current_path = None @@ -119,10 +118,8 @@ def clear_script_prefix(): """ Unset the script prefix for the current thread. """ - try: + with suppress(AttributeError): del _prefixes.value - except AttributeError: - pass def set_urlconf(urlconf_name): |
