Skip to content

Commit

Permalink
don't throw exception when comparing PKey to non-PKey
Browse files Browse the repository at this point in the history
  • Loading branch information
jsonar-cpapke authored and bitprophet committed Apr 25, 2022
1 parent 094a5e1 commit f8036d6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion paramiko/pkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def __cmp__(self, other):
return cmp(self.asbytes(), other.asbytes()) # noqa

def __eq__(self, other):
return self._fields == other._fields
return isinstance(other, PKey) and self._fields == other._fields

def __hash__(self):
return hash(self._fields)
Expand Down
5 changes: 5 additions & 0 deletions tests/test_pkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,11 @@ def test_keys_are_comparable(self):
for key1, key2 in self.keys():
assert key1 == key2

def test_keys_are_not_equal_to_other(self):
for value in [None, True, ""]:
for key1, _ in self.keys():
assert key1 != value

def test_keys_are_hashable(self):
# NOTE: this isn't a great test due to hashseed randomization under
# Python 3 preventing use of static values, but it does still prove
Expand Down

0 comments on commit f8036d6

Please sign in to comment.