CiwPython / Ciw

Ciw is a simulation library for open queueing networks.
http://ciw.readthedocs.io
MIT License
148 stars 42 forks source link

Change `!= None` to `is not` in import_params.py #240

Closed galenseilis closed 6 months ago

galenseilis commented 8 months ago

In Python, the is not None construct is preferred over != None for several reasons:

Identity Comparison vs. Value Comparison:

is not is an identity comparison, which checks whether two objects refer to the same memory location. != is a value comparison, which checks whether the values of the objects are equal.

None is a Singleton:

None is a singleton object in Python, meaning there is only one instance of None in the entire program. Using is not None leverages the identity comparison and takes advantage of the fact that there is only one None object, making it more efficient than a value comparison.

Consistency:

Using is not None is more consistent with the recommended practice of using is and is not for checking against singletons (like None).

Avoids Unintended Behavior:

Value comparisons (!=) may behave unexpectedly when dealing with objects that override the eq method, leading to potential pitfalls. Identity comparisons (is not) are safer in such cases, as they explicitly check for object identity.