msiemens / tinydb

TinyDB is a lightweight document oriented database optimized for your happiness :)
https://tinydb.readthedocs.org
MIT License
6.84k stars 550 forks source link

Argument of type "QueryInstance" cannot be assigned to parameter "cond" of type "QueryLike" #496

Closed saumikn closed 2 years ago

saumikn commented 2 years ago

Using the VS Code Pylance type checker, I'm unable to run queries without giving me type errors. For example, just running db.search(where("field") == field) gives me the error:

Argument of type "QueryInstance" cannot be assigned to parameter "cond" of type "QueryLike" in function "search"
  "QueryInstance" is incompatible with protocol "QueryLike"
    "__hash__" is an incompatible type
      Type "() -> int" cannot be assigned to type "() -> None"
        Function return type "int" is incompatible with type "None"
          Type cannot be assigned to type "None"Pylance[reportGeneralTypeIssues](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportGeneralTypeIssues)

I can fix this if I go into queries.QueryLike, and replace def __hash__(self): ... with def __hash__(self) -> int: ...

If we made this change, would it break other code (e.g. MyPy) in any way?

msiemens commented 2 years ago

Seems like MyPy wasn't too upset about this, so I've added this change in b431412 🙂 (Note that the CI pipeline fails due to issues unrelated to this change). Will be released in the next TinyDB version

saumikn commented 2 years ago

Oh, turns out I was referring to a line which was already fixed in fcb1a86, just that that change hasn't been released yet so it never showed up on my end. Thanks for the quick reply!