clokep / django-querysetsequence

Chain multiple (disparate) QuerySets in Django
https://django-querysetsequence.readthedocs.io/
ISC License
107 stars 25 forks source link

SyntaxWarning: "is not" with a literal. Did you mean "!="? #60

Closed clokep closed 4 years ago

clokep commented 4 years ago

the low_mark comparison is not obviously an error. I get this warning running: python manage.py runserver

/var/venv/lib/python3.8/site-packages/queryset_sequence/init.py:255: SyntaxWarning: "is not" with a literal. Did you mean "!="?
if low_mark is not 0:

For this reason I did that change, maybe, not strictly necessary.

Originally posted by @alfredo-ardito in https://github.com/percipient/django-querysetsequence/issues/58#issuecomment-562550902

clokep commented 4 years ago

I don't see this when running tests on Python 3.7, questions I have:

clokep commented 4 years ago

It looks like this code was originally added in dd3502822ec4b9616aae1b9baaf5342211c992d1, so it has always been that way.

alfredo-ardito commented 4 years ago

I guess this warning comes from Python 3.8 I'll investigate and let you know

clokep commented 4 years ago

Seems to be documented in the changelog:

The compiler now produces a SyntaxWarning when identity checks (is and is not) are used with certain types of literals (e.g. strings, numbers). These can often work by accident in CPython, but are not guaranteed by the language spec. The warning advises users to use equality tests (== and !=) instead. (Contributed by Serhiy Storchaka in bpo-34850.)

I believe your fix was correct to just change it to a !=!

alfredo-ardito commented 4 years ago

okay, good to know.

clokep commented 4 years ago

Thanks for reporting this!