basically, with flask_api and flask_sqlalchemy installed (via pip3), if I run mypy on this
import flask_sqalchemy
import flask_api
the error message is this
testMypy.py:1: error: No library stub file for module 'flask_sqlalchemy'
testMypy.py:1: note: (Stub files are from https://github.com/python/typeshed)
testMypy.py:2: error: Cannot find module named 'flask_api'
testMypy.py:2: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
now, I do know that as of Jan/19/2019, flask_sqlalchemy and flask_api doesn't have stub files in the typeshed (yet), but I think if both modules are installed in the system, the error messages should both be "No library stub file for module ..", what are the difference between these two?
The two error messages mean the same thing. The only difference is that you get the first error message if the module you're importing is considered to be a "popular" third party library -- specifically, if it's one of the modules in this list. In this case, flask_sqlalchemy is a member of that list, but flask_api isn't.
The reason why mypy special-cases these modules is largely for usability: it's somewhat confusing to get an error message like "Cannot find module named 'blah'" when you've seemingly installed it via pip. So, it special-cases 3rd party libraries that are likely to be commonly used so it can at least improve the user experience there.
A follow-up question you might have is "why doesn't mypy just look at what's pip-installed and use the first error message whenever you try importing anything that's pip-installed?". After all, mypy needs to do this anyways to try and find PEP 561 compatible packages -- packages that declare they come bundled with type hints.
Well, mypy probably could be doing that -- but this section of the codebase was added before PEP 561 was a thing (before mypy really needed to be scanning pip-installed packages), and I suspect nobody's really thought about this corner of the codebase for a long time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With