Skip to content

Commit

Permalink
fix lint errors revealed by pycodestyle 2.11
Browse files Browse the repository at this point in the history
When performing isinstance checks, an identity comparison is
automatically done, but we don't use isinstance here because we need
strict identity equality *without allowing subtypes*.

Comparing type() == type() is a value comparison, but could produce
effectively the same results as an identity comparison, usually, despite
being semantically off. pycodestyle learned to detect this and warn you
to do strict identity comparison.

(cherry picked from commit d461536)
  • Loading branch information
eli-schwartz committed Aug 6, 2023
1 parent 4e388b3 commit df2fdc8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion mesonbuild/coredata.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ def update_project_options(self, options: 'MutableKeyedOptionDictType') -> None:
continue

oldval = self.options[key]
if type(oldval) != type(value):
if type(oldval) is not type(value):
self.options[key] = value
elif oldval.choices != value.choices:
# If the choices have changed, use the new value, but attempt
Expand Down
8 changes: 4 additions & 4 deletions mesonbuild/interpreterbase/baseobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ def op_equals(self, other: TYPE_var) -> bool:
# We use `type(...) == type(...)` here to enforce an *exact* match for comparison. We
# don't want comparisons to be possible where `isinstance(derived_obj, type(base_obj))`
# would pass because this comparison must never be true: `derived_obj == base_obj`
if type(self) != type(other):
if type(self) is not type(other):
self._throw_comp_exception(other, '==')
return self == other

def op_not_equals(self, other: TYPE_var) -> bool:
if type(self) != type(other):
if type(self) is not type(other):
self._throw_comp_exception(other, '!=')
return self != other

Expand Down Expand Up @@ -157,12 +157,12 @@ def display_name(self) -> str:
# Override default comparison operators for the held object
def op_equals(self, other: TYPE_var) -> bool:
# See the comment from InterpreterObject why we are using `type()` here.
if type(self.held_object) != type(other):
if type(self.held_object) is not type(other):
self._throw_comp_exception(other, '==')
return self.held_object == other

def op_not_equals(self, other: TYPE_var) -> bool:
if type(self.held_object) != type(other):
if type(self.held_object) is not type(other):
self._throw_comp_exception(other, '!=')
return self.held_object != other

Expand Down

0 comments on commit df2fdc8

Please sign in to comment.