Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
msiemens merged 1 commit intomsiemens:masterfromplaypauseandstop:master
Nov 14, 2020
Merged

feat: Make tinydb PEP 561 compatible#352

msiemens merged 1 commit intomsiemens:masterfromplaypauseandstop:master
Nov 14, 2020

Conversation

@playpauseandstop
Copy link
Contributor

@playpauseandstopplaypauseandstop commentedNov 5, 2020
edited
Loading

PEP 561 defines a way to share type hints for Python packages.

Astinydb already provides type annotations for their modules, add last 2 pieces:py.typed file & PyPI classifier to allowmypy and other static analyzers use TinyDB type annotations.


First of all, thanks a lot for this beautiful piece of software! I'm enjoying usetinydb within my projects.

However, as I recently restrictmypy config I start receiving errors such as,

src/app/contexts.py:5:1: error: Skipping analyzing 'tinydb': found module but no type hints or library stubs  [import]src/app/contexts.py:5:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports

With that in mind I propose to maketinydb package PEP 561 compatible, somypy and other static analyzer users may benefit fromtinydb type hints.

Thanks

ps. BTW, to fix themypy issue above I'm using next config,

[mypy-tinydb.*]ignore_missing_imports = True

[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.
@msiemensmsiemens merged commit77fa426 intomsiemens:masterNov 14, 2020
@msiemens
Copy link
Owner

msiemens commentedNov 14, 2020
edited
Loading

Thanks ❤️

@msiemens
Copy link
Owner

This is now published in v4.3.0 🙂

@playpauseandstop
Copy link
ContributorAuthor

@msiemens

Thanks a lot for merging this intomaster and making new 4.3.0 release, I appreciate it!

After upgrading to new release 95% of TinyDB code works smoothly with mypy and another 5% results in next issues:

  • error: Call to untyped function "TinyDB" in typed context [no-untyped-call]
  • error: Call to untyped function "Query" in typed context [no-untyped-call]
  • error: Argument 1 to "search" of "Table" has incompatible type "QueryInstance"; expected "Query" [arg-type]

Any of these issues are critical for me, so for now I justtype: ignore'd them.

@msiemens
Copy link
Owner

After upgrading to new release 95% of TinyDB code works smoothly with mypy and another 5% results in next issues:

Good to hear that most of the code now passes. Do you have line numbers for the remaining errors?

@playpauseandstop
Copy link
ContributorAuthor

Do you have line numbers for the remaining errors?

As the errors are in my code, I'm copy-pasting the code (with# type: ignore comments) below,

Call to untyped function "TinyDB" in typed context

withTinyDB(settings.tinydb_path)asdb:# type: ignore[no-untyped-call]        ...

Call to untyped function "Query" in typed context

Q=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
Copy link
Owner

I looked into the type errors again and it turns out that not specifiying the return type on an__init__ method makes it untyped:

if__init__ has no annotated arguments and no return type annotation, it is considered an untyped method:

https://mypy.readthedocs.io/en/stable/class_basics.html#annotating-init-methods

I've pushed a fix which will be included in the next release.

Argument 1 to "search" of "Table" has incompatible type "QueryInstance"; expected "Query"

Regarding this error it's more complicated as MyPy is technically correct:Query is a subclass ofQueryInstance, not the other way around. Thus a function that expect aQuery object won't acceptQueryInstance objects. But in practice this works becauseQueryInstance has a__call__ method to evaluate itself which is inherited toQuery. I'll have to let this open for now

playpauseandstop reacted with thumbs up emoji

@msiemens
Copy link
Owner

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 🙂

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@playpauseandstop@msiemens

[8]ページ先頭

©2009-2025 Movatter.jp