Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mypy error: found module but no type hints or library stubs #331

Closed
andreaslongo opened this issue Oct 14, 2021 · 2 comments
Closed

Mypy error: found module but no type hints or library stubs #331

andreaslongo opened this issue Oct 14, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@andreaslongo
Copy link

andreaslongo commented Oct 14, 2021

Python 3.9.5
mypy 0.910
sqlite-utils 3.17.1

While using sqlite-utils as a library, when I use mypy for static type checking, it throws an error:

mypy .
src/etl.py:5: error: Skipping analyzing "sqlite_utils": found module but no type hints or library stubs
    import sqlite_utils
    ^
src/etl.py:5: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
test/test_etl.py:4: error: Skipping analyzing "sqlite_utils": found module but no type hints or library stubs
    import sqlite_utils
    ^
Found 2 errors in 2 files (checked 7 source files)

When I add a py.typed file to the sqlite-utils package to mark it as PEP 561 compatible, the error goes away.

al@nbal ..b/python3.9/site-packages/sqlite_utils (git)-[main] % la
total 200
drwx------   3 al al   4096 Oct 14 22:00 .
drwx------ 117 al al   4096 Oct 12 21:12 ..
-rw-------   1 al al  64409 Oct 12 21:11 cli.py
-rw-------   1 al al 109092 Oct 12 21:11 db.py
-rw-------   1 al al      0 Oct 14 22:00 py.typed
-rw-------   1 al al    684 Oct 12 21:11 recipes.py
-rw-------   1 al al   7988 Oct 12 21:11 utils.py
-rw-------   1 al al    113 Oct 12 21:11 __init__.py

I would like to suggest adding a py.typed file to the repository.

See also the mypy docs on creating PEP 561 compatible packages:
https://mypy.readthedocs.io/en/stable/installed_packages.html#creating-pep-561-compatible-packages

@simonw simonw added the enhancement New feature or request label Nov 14, 2021
@simonw
Copy link
Owner

simonw commented Nov 14, 2021

Thanks - I didn't know this was needed!

@simonw
Copy link
Owner

simonw commented Nov 14, 2021

Tested it like this, against a freshly built .tar.gz package from my development environment:

(w) w % mypy .                    
hello.py:1: error: Skipping analyzing "sqlite_utils": found module but no type hints or library stubs
hello.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 1 source file)
(w) w % pip install ~/Dropbox/Development/sqlite-utils/dist/sqlite-utils-3.17.1.tar.gz
Processing /Users/simon/Dropbox/Development/sqlite-utils/dist/sqlite-utils-3.17.1.tar.gz
...
Successfully installed sqlite-utils-3.17.1
(w) w % mypy .                                                                        
Success: no issues found in 1 source file

I tested against the .whl too.

My hello.py script contained this:

import sqlite_utils
from typing import cast

if __name__ == "__main__":
    db = sqlite_utils.Database(memory=True)
    table = cast(sqlite_utils.db.Table, db["foo"])
    table.insert({"id": 5})
    print(list(db.query("select * from foo")))

That cast() is necessary because without it you get this error:

(w) w % mypy .
hello.py:7: error: Item "View" of "Union[Table, View]" has no attribute "insert"

@simonw simonw closed this as completed in 73e214a Nov 14, 2021
simonw added a commit that referenced this issue Nov 14, 2021
simonw added a commit that referenced this issue Nov 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants