We had been using the python-memcached library for memcached access for a long time, and recently noticed warnings like the following under Python 3.8:
1 | memcache.py:1303: SyntaxWarning: "is" with a literal. Did you mean "=="? |
After checking the python-memcached source code, which is basically a single file, the problematic lines were easy to find:
1 | if key is '': |
That pattern is no longer acceptable in Python 3.8.
Even though it is “just” a warning, it is still noisy and unpleasant in logs, so I wanted to fix it.
I then checked the official GitHub repository and found that the project has not really been maintained for quite a while. Even though there is already a PR for this issue, it has not been merged:
https://github.com/linsomniac/python-memcached/issues/176
So there are basically two practical options:
- Patch
memcache.pydirectly in your environment and replaceiswith==in those lines. - Since we distribute a
requirements.txt, I published a fixed package to PyPI, which you can install directly if needed:
1 | pip install python-memcached-py38fix |
At this point, moving to pymemcache is probably the more sensible long-term direction anyway, especially since Django has already dropped support for python-memcached.