Skip to content

ruff doesn't find the same E721 violations as new flake8 does #12290

Closed
@timj

Description

I searched for E721 but couldn't find a previous ticket.

ruff 0.5.1

For the file https://github.com/lsst/geom/blob/main/tests/test_coordinates.py flake8 7.1.0 reports this error:

tests/test_coordinates.py:299:16: E721 do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()`

The relevant line is:

if type(result) != expected:

ruff 0.5.1 does not report any E721 violation. There is no ruff configuration in this directory when I clone.

I have other examples of inconsistency. In https://github.com/lsst/fgcm flake8 reports:

/fgcm/fgcmConfig.py:30:20: E721 do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()`
./fgcm/fgcmConfig.py:33:20: E721 do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()`
./fgcm/fgcmConfig.py:59:16: E721 do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()`

ruff reports:

fgcm/fgcmConfig.py:33:20: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
   |
31 |                     raise TypeError("Default is the wrong datatype.")
32 |             if self._value is not None:
33 |                 if type(self._value) != datatype:
   |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ E721
34 |                     raise TypeError("Value is the wrong datatype.")
   |

fgcm/fgcmConfig.py:59:16: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
   |
58 |         if self._datatype is not None:
59 |             if type(self._value) != self._datatype:
   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ E721
60 |                 raise ValueError("Datatype mismatch for %s (got %s, expected %s)" %
61 |                                  (name, str(type(self._value)), str(self._datatype)))
   |

fgcm/sharedNumpyMemManager.py:100:15: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
    |
 98 |         elif (dtype == np.int16):
 99 |             ctype = ctypes.c_int16
100 |         elif (dtype == bool):
    |               ^^^^^^^^^^^^^ E721
101 |             ctype = ctypes.c_bool
102 |         else:
    |

where two of the warnings agree but flake8 is reporting one from line 30 of fgcmConfig.py which ruff does not report, and ruff reports one from sharedNumpyMemManager.py that flake8 does not report.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions