.. _CompareSingletonPrimitivesByIsRule:

==================================
CompareSingletonPrimitivesByIsRule
==================================

Enforces the use of `is` and `is not` in comparisons to singleton primitives (None, True, False) rather than == and !=.
The == operator checks equality, when in this scenario, we want to check identity.
See Flake8 rules E711 (https://www.flake8rules.com/rules/E711.html) and E712 (https://www.flake8rules.com/rules/E712.html).

-------
Message
-------
Comparisons to singleton primitives should not be done with == or !=, as they check equality rather than identiy. Use `is` or `is not` instead.

----------------
Has Autofix: Yes
----------------

-------------------
VALID Code Examples
-------------------

# 1:







.. code-block:: python

            if x: pass




# 2:







.. code-block:: python

            if not x: pass




# 3:







.. code-block:: python

            x is True




.. container:: toggle


    # 4:







    .. code-block:: python

                x is False





    # 5:







    .. code-block:: python

                x is None





    # 6:







    .. code-block:: python

                x is not None





    # 7:







    .. code-block:: python

                x is True is not y





    # 8:







    .. code-block:: python

                y is None is not x





    # 9:







    .. code-block:: python

                None is y





    # 10:







    .. code-block:: python

                True is x





    # 11:







    .. code-block:: python

                False is x





    # 12:







    .. code-block:: python

                x == 2





    # 13:







    .. code-block:: python

                2 != x





---------------------
INVALID Code Examples
---------------------

# 1:







.. code-block:: python

            x != True




Autofix:

.. code-block:: python

    --- 
    +++ 
    @@ -1 +1 @@
    -x != True
    +x is not True

# 2:







.. code-block:: python

            x != False




Autofix:

.. code-block:: python

    --- 
    +++ 
    @@ -1 +1 @@
    -x != False
    +x is not False

# 3:







.. code-block:: python

            x == False




Autofix:

.. code-block:: python

    --- 
    +++ 
    @@ -1 +1 @@
    -x == False
    +x is False

.. container:: toggle


    # 4:







    .. code-block:: python

                x == None




    Autofix:

    .. code-block:: python

        --- 
        +++ 
        @@ -1 +1 @@
        -x == None
        +x is None


    # 5:







    .. code-block:: python

                x != None




    Autofix:

    .. code-block:: python

        --- 
        +++ 
        @@ -1 +1 @@
        -x != None
        +x is not None


    # 6:







    .. code-block:: python

                False == x




    Autofix:

    .. code-block:: python

        --- 
        +++ 
        @@ -1 +1 @@
        -False == x
        +False is x


    # 7:







    .. code-block:: python

                x is True == y




    Autofix:

    .. code-block:: python

        --- 
        +++ 
        @@ -1 +1 @@
        -x is True == y
        +x is True is y

