This is a real bug. "is" is identity (pointer) comparison, like comparing
char* in C using "==", so it is usually wrong for anything that isn't
a singleton object such as None.

On Fri, 27 Aug 2021 at 13:16:55 -0400, The Wanderer wrote:
> Setting up python3-fife (0.4.2-3) ...
> /usr/lib/python3/dist-packages/fife/extensions/fife_settings.py:301:
> SyntaxWarning: "is not" with a literal. Did you mean "!="?
>   if module is not "FIFE":

My understanding is that this is genuinely a functional bug: non-trivial
strings in Python are usually allocated separately, so this is like doing
"if (module == "FIFE")" in C, and in practice they will usually compare
unequal, even if module is another string containing the letters "FIFE".

> /usr/lib/python3/dist-packages/fife/extensions/pychan/widgets/curvegraph.py:164:
> SyntaxWarning: "is" with a literal. Did you mean "=="?
>   if coordinates is None or len(coordinates) is 0:

In CPython, the reference C implementation of Python, integers in a
certain range (I think it's something like -1 to 100) are "interned", so
comparison with "is" will do what the programmer intends - but that's an
implementation detail that might change in a future version, and should
not be relied on. Larger integers are allocated and freed on-demand,
so they will usually compare unequal with "is", even if the numerical
value is equal. Relying on this implementation detail is not portable
to other implementations such as PyPy, and is considered to be bad style
even in CPython.

Conversely, None is a special singleton object, so comparing with
"is None" or "is not None" is correct (and is considered to be good
style).

    smcv

Reply via email to