Query syntax causing pylint "singleton-comparison" and flake8 E712
Hey there! I'm trying to use tinydb in a project using mypy (thanks for the plugin), pylint and flake8. While mypy works and understands the query syntax thanks to the provided plugin, pylint and flake8 will complain about the following:
database.search(query["test"] == True)
pylint: singleton-comparison error: should be "query["test"] is True"
flake8: E712 use "if query["test"] is True: or if query["test"]:"
Apparently using those syntax changes as advised by these linting frameworks results in an error, because then the query is not a Callable anymore but directly a boolean value.
The only thing I found to "work" is to silence both linters on every line that makes use of the query language. Please tell me I'm just stupid and there is another, straight forward way of doing this :pray:
"Fun"-fact: I tried to circumvent this by passing a lambda function as query which works in code and pleases pylint and flake8 but then mypy will start to break out in tears because there is an obvious type mismatch between some random Callable and a a QueryLike object.
Hey @w4tsn! I fear that this is a limitation of tools that only inspect the syntax (or rather the AST) but have no insight into what types are involved at runtime. I don't think that there is much that TinyDB can do in this regard short of fundamentally changing how the query mechanism works.
That being said, I think there are two ways forward for this:
- Write a plugin for Pylint and/or Flake8 to teach them that TinyDB is right in this case. As far as I can tell, both Pylint and Flake8 have support for plugins.
- Maybe Pylint and Flake8 can be tricked by calling
Query's__eq__directly, something like this:query["test"].__eq__(True). This doesn't look as good as the regular syntax but might be easier than writing a plugin for Pylint/Flake8.
Does one of these options work for you?
Closing due to inactivity. Feel free to re-open it it's still an issue.