thp / minidb

Store Python objects in SQLite 3. Concise, pythonic API. Easy to write, relatively easy to read. A kind of super simple ORM, if you will. Give it a try.

Home Page:https://thp.io/2010/minidb/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Python 3.8 Syntax Warning

CaseyFaist opened this issue · comments

commented

Hi! When working on urlwatch, I ran into the following warning while running the project with Python 3.8.2:

/.../urlwatch/venv/lib/python3.8/site-packages/minidb-2.0.2-py3.8.egg/minidb.py:144: SyntaxWarning: "is" with a literal. Did you mean "=="?

I also encountered this error when importing it via python repl, and when trying to run the tests.

I can confirm that downgrading the environment to 3.7 resolves the warning - and found a description of this change in Python 3.8 here:
https://adamj.eu/tech/2020/01/21/why-does-python-3-8-syntaxwarning-for-is-literal/

This is a warning, and not a breaking issue - and it's possible to silence the warning:
https://docs.python.org/2/library/warnings.html#temporarily-suppressing-warnings

But also, the change required to correct the issue looks minimal, and the warning has been introduced to highlight potentially unexpected behavior in the previous convention.

The biggest issue with this warning is that downstream developers, using a project that uses minidb (such as urlwatch). The warning adds confusion for them (took me a second to confirm my environment was properly configured), and they may mistake it as an error traceback and think something's wrong.

Suggested fix is to convert the is statements here to == as recommended by the warning, as this is also backwards compatible with Python 3.7, 3.6 and 2.7:
https://github.com/thp/minidb/blob/master/minidb.py#L144

Happy to submit the PR if my suggested fix is acceptable 🎉

Related to #11, feel free to check (after reading that PR) what's the best way and submit a PR.

This should be fixed in the just-released minidb 2.0.3, please let me know if you still have issues after upgrading the package:

python3 -m pip install --upgrade minidb