basilisp.core/nil?
SyntaxWarning with numeric constants
#996
Labels
Milestone
basilisp.core/nil?
SyntaxWarning with numeric constants
#996
Hi,
starting with Python 3.8, using
basilisp.core/nil?
with a numeric literal triggers a SyntaxWarning:To reproduce, open up the REPL and call
nil?
with a numeric argument, you should see the warningThis warning also appears during running the test suite, as some macro-expanded code includes nil? with a literal as its first argument. For example:
The underlying issue is that
basilisp.core/nil?
is defined using Python’s is operatorHowever, the is operator should not be used with string or numeric literals, as outlined in https://bugs.python.org/issue34850
and made it into a SyntaxWarning since Python 3.8.
Although comparing a literal with nil/None (as we do in this function) might not cause problems, I believe the warning needs to be addressed.
A solution can be to use the
==
operator instead innil?
, but PEP-8 suggests comparison toNone
should only be done withis
:Perhaps a better solution could be to implement `nil? in the compiler, where the analyzer can check if the argument is a literal and decide accordingly?
Thanks
The text was updated successfully, but these errors were encountered: