[2.2.x] Fixed #30215 -- Fixed autoreloader crash for modules without __spec__.
Regression inc8720e7696
. Backport of99cfb28e99
from master.
This commit is contained in:
parent
7331dd8a98
commit
4dac17ac93
1
AUTHORS
1
AUTHORS
|
@ -280,6 +280,7 @@ answer newbie questions, and generally made Django that much better:
|
||||||
Flávio Juvenal da Silva Junior <flavio@vinta.com.br>
|
Flávio Juvenal da Silva Junior <flavio@vinta.com.br>
|
||||||
flavio.curella@gmail.com
|
flavio.curella@gmail.com
|
||||||
Florian Apolloner <florian@apolloner.eu>
|
Florian Apolloner <florian@apolloner.eu>
|
||||||
|
Florian Moussous <florian.moussous@gmail.com>
|
||||||
Francisco Albarran Cristobal <pahko.xd@gmail.com>
|
Francisco Albarran Cristobal <pahko.xd@gmail.com>
|
||||||
François Freitag <mail@franek.fr>
|
François Freitag <mail@franek.fr>
|
||||||
Frank Tegtmeyer <fte@fte.to>
|
Frank Tegtmeyer <fte@fte.to>
|
||||||
|
|
|
@ -111,7 +111,7 @@ def iter_modules_and_files(modules, extra_files):
|
||||||
# During debugging (with PyDev) the 'typing.io' and 'typing.re' objects
|
# During debugging (with PyDev) the 'typing.io' and 'typing.re' objects
|
||||||
# are added to sys.modules, however they are types not modules and so
|
# are added to sys.modules, however they are types not modules and so
|
||||||
# cause issues here.
|
# cause issues here.
|
||||||
if not isinstance(module, ModuleType) or module.__spec__ is None:
|
if not isinstance(module, ModuleType) or getattr(module, '__spec__', None) is None:
|
||||||
continue
|
continue
|
||||||
spec = module.__spec__
|
spec = module.__spec__
|
||||||
# Modules could be loaded from places without a concrete location. If
|
# Modules could be loaded from places without a concrete location. If
|
||||||
|
|
|
@ -6,6 +6,7 @@ import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
import types
|
||||||
import weakref
|
import weakref
|
||||||
import zipfile
|
import zipfile
|
||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
|
@ -124,6 +125,11 @@ class TestIterModulesAndFiles(SimpleTestCase):
|
||||||
self.addCleanup(lambda: sys.modules.pop('time_proxy', None))
|
self.addCleanup(lambda: sys.modules.pop('time_proxy', None))
|
||||||
list(autoreload.iter_all_python_module_files()) # No crash.
|
list(autoreload.iter_all_python_module_files()) # No crash.
|
||||||
|
|
||||||
|
def test_module_without_spec(self):
|
||||||
|
module = types.ModuleType('test_module')
|
||||||
|
del module.__spec__
|
||||||
|
self.assertEqual(autoreload.iter_modules_and_files((module,), frozenset()), frozenset())
|
||||||
|
|
||||||
|
|
||||||
class TestCommonRoots(SimpleTestCase):
|
class TestCommonRoots(SimpleTestCase):
|
||||||
def test_common_roots(self):
|
def test_common_roots(self):
|
||||||
|
|
Loading…
Reference in New Issue