File tree Expand file tree Collapse file tree 3 files changed +23
-2
lines changed Expand file tree Collapse file tree 3 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,9 @@ Version 0.10.2
21
21
(bugfix release, release date to be announced)
22
22
23
23
- Fixed broken `test_appcontext_signals()` test case.
24
+ - Raise an :exc:`AttributeError` in :func:`flask.helpers.find_package` with a
25
+ useful message explaining why it is raised when a PEP 302 import hook is used
26
+ without an `is_package()` method.
24
27
25
28
Version 0.10.1
26
29
--------------
Original file line number Diff line number Diff line change @@ -679,8 +679,13 @@ def find_package(import_name):
679
679
filename = sys .modules [import_name ].__file__
680
680
package_path = os .path .abspath (os .path .dirname (filename ))
681
681
# package_path ends with __init__.py for a package
682
- if loader .is_package (root_mod_name ):
683
- package_path = os .path .dirname (package_path )
682
+ if hasattr (loader , 'is_package' ):
683
+ if loader .is_package (root_mod_name ):
684
+ package_path = os .path .dirname (package_path )
685
+ else :
686
+ raise AttributeError (
687
+ ('%s.is_package() method is missing but is '
688
+ 'required by Flask of PEP 302 import hooks' ) % loader .__class__ .__name__ )
684
689
685
690
site_parent , site_folder = os .path .split (package_path )
686
691
py_prefix = os .path .abspath (sys .prefix )
Original file line number Diff line number Diff line change 16
16
import unittest
17
17
from contextlib import contextmanager
18
18
from flask .testsuite import FlaskTestCase
19
+ from flask ._compat import PY2
19
20
20
21
21
22
# config keys used for the ConfigTestCase
@@ -291,6 +292,18 @@ def test_egg_installed_paths(self):
291
292
if 'site_egg' in sys .modules :
292
293
del sys .modules ['site_egg' ]
293
294
295
+ if PY2 :
296
+ def test_meta_path_loader_without_is_package (self ):
297
+ class Loader (object ):
298
+ def find_module (self , name ):
299
+ return self
300
+ sys .meta_path .append (Loader ())
301
+ try :
302
+ with self .assert_raises (AttributeError ):
303
+ flask .Flask (__name__ )
304
+ finally :
305
+ sys .meta_path .pop ()
306
+
294
307
295
308
def suite ():
296
309
suite = unittest .TestSuite ()
You can’t perform that action at this time.
0 commit comments