diff options
| author | Tim Graham <timograham@gmail.com> | 2017-09-07 08:16:21 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-09-07 08:16:21 -0400 |
| commit | 6e4c6281dbb7ee12bcdc22620894edb4e9cf623f (patch) | |
| tree | 1c21218d4b6f00c499f18943d5190ebe7b5248c9 /django/urls | |
| parent | 8b2515a450ef376b9205029090af0a79c8341bd7 (diff) | |
Reverted "Fixed #27818 -- Replaced try/except/pass with contextlib.suppress()."
This reverts commit 550cb3a365dee4edfdd1563224d5304de2a57fda
because try/except performs better.
Diffstat (limited to 'django/urls')
| -rw-r--r-- | django/urls/base.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/django/urls/base.py b/django/urls/base.py index 26084dbe3e..6dccdd2e7d 100644 --- a/django/urls/base.py +++ b/django/urls/base.py @@ -1,4 +1,3 @@ -from contextlib import suppress from threading import local from urllib.parse import urlsplit, urlunsplit @@ -54,7 +53,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. - with suppress(KeyError): + try: 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: @@ -65,6 +64,8 @@ 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 @@ -118,8 +119,10 @@ def clear_script_prefix(): """ Unset the script prefix for the current thread. """ - with suppress(AttributeError): + try: del _prefixes.value + except AttributeError: + pass def set_urlconf(urlconf_name): |
