Explain is_package AttributeError in find_package
When a PEP 302 import hook is used that doesn't implement .is_package() an AttributeError is raised. This looks like a bug in Flask. This change fixes that problem in the sense that it explains, that the AttributeError is intentional.
This commit is contained in:
parent
f606a6d6a1
commit
94f4360137
3 changed files with 23 additions and 2 deletions
|
|
@ -679,8 +679,13 @@ def find_package(import_name):
|
|||
filename = sys.modules[import_name].__file__
|
||||
package_path = os.path.abspath(os.path.dirname(filename))
|
||||
# package_path ends with __init__.py for a package
|
||||
if loader.is_package(root_mod_name):
|
||||
package_path = os.path.dirname(package_path)
|
||||
if hasattr(loader, 'is_package'):
|
||||
if loader.is_package(root_mod_name):
|
||||
package_path = os.path.dirname(package_path)
|
||||
else:
|
||||
raise AttributeError(
|
||||
('%s.is_package() method is missing but is '
|
||||
'required by Flask of PEP 302 import hooks') % loader.__class__.__name__)
|
||||
|
||||
site_parent, site_folder = os.path.split(package_path)
|
||||
py_prefix = os.path.abspath(sys.prefix)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue