byuccl / spydrnet-tmr

TMR utilities for the SpyDrNet project
https://byuccl.github.io/spydrnet-tmr/
BSD 3-Clause "New" or "Revised" License
4 stars 2 forks source link

Don't use 'is' operator with integer literals (== preferred). #17

Closed gsmecher closed 1 year ago

gsmecher commented 1 year ago

Python 3.10 helpfully emits the following warning:

/path/to/spydrnet-tmr/spydrnet_tmr/transformation/replication/organ_insertion.py:664: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if start_index is -1:

The current code does work as intended, but relies on small-number singletons ("interning") that are a Python implementation detail. For example:


>>> a = 1234567890
>>> b = 1234567890
>>> a is b
False
>>> c = -1
>>> d = -1
>>> c is d
True

So, this pull request should not alter behaviour - it just makes the code correct-er.

jacobdbrown4 commented 1 year ago

Thanks for bringing this to our attention. The change has been made.