mirror of
https://github.com/django/django.git
synced 2025-06-03 18:49:12 +00:00
Reverted "Fixed #35564 -- Improved readability of subclass identification."
This reverts commit f0d05a747f7a099e6c6bc58c42a787546d2212e7 due to a performance regression.
This commit is contained in:
parent
8719a6181e
commit
8cfcf9a30e
@ -1,5 +1,4 @@
|
|||||||
import collections
|
import collections
|
||||||
import contextlib
|
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
@ -22,9 +21,10 @@ def _issubclass(cls, classinfo):
|
|||||||
issubclass() variant that doesn't raise an exception if cls isn't a
|
issubclass() variant that doesn't raise an exception if cls isn't a
|
||||||
class.
|
class.
|
||||||
"""
|
"""
|
||||||
with contextlib.suppress(TypeError):
|
try:
|
||||||
return issubclass(cls, classinfo)
|
return issubclass(cls, classinfo)
|
||||||
return False
|
except TypeError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def _contains_subclass(class_path, candidate_paths):
|
def _contains_subclass(class_path, candidate_paths):
|
||||||
@ -34,9 +34,13 @@ def _contains_subclass(class_path, candidate_paths):
|
|||||||
"""
|
"""
|
||||||
cls = import_string(class_path)
|
cls = import_string(class_path)
|
||||||
for path in candidate_paths:
|
for path in candidate_paths:
|
||||||
with contextlib.suppress(ImportError, TypeError):
|
try:
|
||||||
if issubclass(import_string(path), cls):
|
candidate_cls = import_string(path)
|
||||||
return True
|
except ImportError:
|
||||||
|
# ImportErrors are raised elsewhere.
|
||||||
|
continue
|
||||||
|
if _issubclass(candidate_cls, cls):
|
||||||
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import contextlib
|
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
from types import MethodType
|
from types import MethodType
|
||||||
|
|
||||||
@ -16,10 +15,13 @@ def _subclass_index(class_path, candidate_paths):
|
|||||||
list of candidate paths. If it does not exist, return -1.
|
list of candidate paths. If it does not exist, return -1.
|
||||||
"""
|
"""
|
||||||
cls = import_string(class_path)
|
cls = import_string(class_path)
|
||||||
for i, path in enumerate(candidate_paths):
|
for index, path in enumerate(candidate_paths):
|
||||||
with contextlib.suppress(ImportError, TypeError):
|
try:
|
||||||
if issubclass(import_string(path), cls):
|
candidate_cls = import_string(path)
|
||||||
return i
|
if issubclass(candidate_cls, cls):
|
||||||
|
return index
|
||||||
|
except (ImportError, TypeError):
|
||||||
|
continue
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user