Skip to content

Commit

Permalink
Remove a pytype: disable by adding some filtering to compare.py.
Browse files Browse the repository at this point in the history
I noticed when exporting our latest changes to GitHub that we had to add a
disable for an unsupported-operands error. The error seems to be a false
positive, caused by some missing filtering in compare.py.

While I was touching the comparison code, I also fixed a lint warning.

PiperOrigin-RevId: 392545719
  • Loading branch information
rchen152 committed Aug 23, 2021
1 parent 8378eeb commit bf8b234
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pytype/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def _is_equality_cmp(op):
def _compare_constants(op, left, right):
try:
return slots.COMPARES[op](left, right)
except TypeError:
raise CmpTypeError()
except TypeError as e:
raise CmpTypeError() from e


def _compare_primitive_constant(vm, op, left, right):
Expand Down
2 changes: 1 addition & 1 deletion pytype/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ def unique_sorted_errors(self):
# f("world") # same error, different backtrace
# so we'll report this error multiple times with different backtraces.
continue
elif traceback_cmp < 0: # pytype: disable=unsupported-operands
elif traceback_cmp < 0:
# If the current traceback is shorter, use the current error instead
# of the previous one.
errors.remove(previous_error)
Expand Down
3 changes: 2 additions & 1 deletion pytype/vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2347,7 +2347,8 @@ def _cmp_rel(self, state, op_name, x, y):
val = compare.cmp_rel(self, op, b1.data, b2.data)
except compare.CmpTypeError:
val = None
self.errorlog.unsupported_operands(self.frames, op, x, y)
if state.node.HasCombination([b1, b2]):
self.errorlog.unsupported_operands(self.frames, op, x, y)
if val is None:
leftover_x.AddBinding(b1.data, {b1}, state.node)
leftover_y.AddBinding(b2.data, {b2}, state.node)
Expand Down

0 comments on commit bf8b234

Please sign in to comment.