- Notifications
You must be signed in to change notification settings - Fork590
feat: Make tinydb PEP 561 compatible#352
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
[PEP 561](https://www.python.org/dev/peps/pep-0561/) defines a way toshare type hints for Python packages.As `tinydb` already provides type annotations for their modules, addlast 2 pieces: `py.typed` file & PyPI classifier to allow `mypy` andother static analyzers use TinyDB type annotations.
msiemens commentedNov 14, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Thanks ❤️ |
msiemens commentedNov 14, 2020
This is now published in v4.3.0 🙂 |
playpauseandstop commentedNov 24, 2020
Thanks a lot for merging this into After upgrading to new release 95% of TinyDB code works smoothly with mypy and another 5% results in next issues:
Any of these issues are critical for me, so for now I just |
msiemens commentedNov 24, 2020
Good to hear that most of the code now passes. Do you have line numbers for the remaining errors? |
playpauseandstop commentedNov 24, 2020
As the errors are in my code, I'm copy-pasting the code (with Call to untyped function "TinyDB" in typed contextwithTinyDB(settings.tinydb_path)asdb:# type: ignore[no-untyped-call] ... Call to untyped function "Query" in typed contextQ=Query()# type: ignore Argument 1 to "search" of "Table" has incompatible type "QueryInstance"; expected "Query"defsearch_stuff(db:TinyDB,*,external_uids:Tuple[uuid.UUID, ...])->Tuple[StuffItem, ...]:returntuple(from_dict(StuffItem,item)foritemindb.table(TABLE_STUFF).search(where(# type: ignore[arg-type]"external_uid" ).one_of([str(item)foriteminexternal_uids]) ) ) |
msiemens commentedDec 30, 2020
I looked into the type errors again and it turns out that not specifiying the return type on an
I've pushed a fix which will be included in the next release.
Regarding this error it's more complicated as MyPy is technically correct: |
msiemens commentedJun 26, 2021
Just a quick note: TinyDB v4.5.0 now includes a fix for the Query error by providing a protocol for Query-like objects which both Query and QueryInstance implement 🙂 |
Uh oh!
There was an error while loading.Please reload this page.
PEP 561 defines a way to share type hints for Python packages.
As
tinydbalready provides type annotations for their modules, add last 2 pieces:py.typedfile & PyPI classifier to allowmypyand other static analyzers use TinyDB type annotations.First of all, thanks a lot for this beautiful piece of software! I'm enjoying use
tinydbwithin my projects.However, as I recently restrict
mypyconfig I start receiving errors such as,With that in mind I propose to make
tinydbpackage PEP 561 compatible, somypyand other static analyzer users may benefit fromtinydbtype hints.Thanks
ps. BTW, to fix the
mypyissue above I'm using next config,