[3.2.x] Refs #32074 -- Fixed find_module()/find_loader() warnings on Python 3.10+.

Backport of f1bcaa9be8 from main.
This commit is contained in:
Mariusz Felisiak 2021-09-16 20:20:54 +02:00
parent d0dc446444
commit f6726fdc3e
2 changed files with 26 additions and 18 deletions

View File

@ -14,6 +14,7 @@ PY36 = sys.version_info >= (3, 6)
PY37 = sys.version_info >= (3, 7)
PY38 = sys.version_info >= (3, 8)
PY39 = sys.version_info >= (3, 9)
PY310 = sys.version_info >= (3, 10)
def get_version(version=None):

View File

@ -9,6 +9,7 @@ from django.test.utils import extend_sys_path
from django.utils.module_loading import (
autodiscover_modules, import_string, module_has_submodule,
)
from django.utils.version import PY310
class DefaultLoader(unittest.TestCase):
@ -184,7 +185,15 @@ class AutodiscoverModulesTestCase(SimpleTestCase):
self.assertEqual(site._registry, {'lorem': 'ipsum'})
class TestFinder:
if PY310:
class TestFinder:
def __init__(self, *args, **kwargs):
self.importer = zipimporter(*args, **kwargs)
def find_spec(self, path, target=None):
return self.importer.find_spec(path, target)
else:
class TestFinder:
def __init__(self, *args, **kwargs):
self.importer = zipimporter(*args, **kwargs)
@ -194,8 +203,7 @@ class TestFinder:
return
return TestLoader(importer)
class TestLoader:
class TestLoader:
def __init__(self, importer):
self.importer = importer
@ -207,9 +215,8 @@ class TestLoader:
class CustomLoader(EggLoader):
"""The Custom Loader test is exactly the same as the EggLoader, but
it uses a custom defined Loader and Finder that is intentionally
split into two classes. Although the EggLoader combines both functions
into one class, this isn't required.
it uses a custom defined Loader class. Although the EggLoader combines both
functions into one class, this isn't required.
"""
def setUp(self):
super().setUp()