Skip to content

flask requires is_package from import loaders, however this api is optional since PEP 451 #3275

@asottile

Description

@asottile

For more information: pytest-dev/pytest#5532

https://www.python.org/dev/peps/pep-0451/#api-changes

A compliant PEP 451 loader can avoid a lot of the tricky APIs just through implementing find_spect -- in this case is_package is replaced by submodule_search_locations being truthy

I'll see if I can't take a stab at this, it looks like this is a reopen of #487

Here's a minimal example:

import flask

app = flask.Flask(__name__)

def test():
    pass
$ pytest t.py
============================= test session starts ==============================
platform linux -- Python 3.6.7, pytest-5.0.0, py-1.8.0, pluggy-0.12.0
rootdir: /tmp/x
collected 0 items / 1 errors                                                   

==================================== ERRORS ====================================
____________________________ ERROR collecting t.py _____________________________
t.py:3: in <module>
    app = flask.Flask(__name__)
venv/lib/python3.6/site-packages/flask/app.py:381: in __init__
    instance_path = self.auto_find_instance_path()
venv/lib/python3.6/site-packages/flask/app.py:678: in auto_find_instance_path
    prefix, package_path = find_package(self.import_name)
venv/lib/python3.6/site-packages/flask/helpers.py:826: in find_package
    loader, root_mod_name):
venv/lib/python3.6/site-packages/flask/helpers.py:789: in _matching_loader_thinks_module_is_package
    loader.__class__.__name__)
E   AttributeError: AssertionRewritingHook.is_package() method is missing but is required by Flask of PEP 302 import hooks.  If you do not use import hooks and you encounter this error please file a bug against Flask.
!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!
=========================== 1 error in 0.31 seconds ============================
$ pip freeze --all
atomicwrites==1.3.0
attrs==19.1.0
Click==7.0
Flask==1.0.3
importlib-metadata==0.18
itsdangerous==1.1.0
Jinja2==2.10.1
MarkupSafe==1.1.1
more-itertools==7.1.0
packaging==19.0
pip==19.1.1
pluggy==0.12.0
py==1.8.0
pyparsing==2.4.0
pytest==5.0.0
setuptools==41.0.1
six==1.12.0
wcwidth==0.1.7
Werkzeug==0.15.4
wheel==0.33.4
zipp==0.5.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions