Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Apr 3, 2024
Merged

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

merged 1 commit into from
Apr 3, 2024

Conversation

galenseilis
Copy link
Contributor

@galenseilis galenseilis commented Jan 7, 2024

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.

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.
@galenseilis galenseilis changed the title Change != to is not in import_params.py Change != None to is not in import_params.py Jan 7, 2024
@geraintpalmer geraintpalmer changed the base branch from master to impovements_from_PRs April 3, 2024 13:12
@geraintpalmer geraintpalmer merged commit 8626345 into CiwPython:impovements_from_PRs Apr 3, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants