Skip to content

Commit

Permalink
fix when == throws (#461)
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra authored Feb 3, 2022
1 parent b0ea964 commit 39fd292
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- Fix internal error when an `__eq__` method throws (#461)
- Fix handling of `async def` methods in stubs (#459)
- Treat Thrift enums as compatible with protocols that
`int` is compatible with (#457)
Expand Down
6 changes: 3 additions & 3 deletions pyanalyze/value.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def function(x: int, y: list[int], z: Any):
import pyanalyze
from pyanalyze.extensions import CustomCheck

from .safe import all_of_type, safe_issubclass, safe_isinstance
from .safe import all_of_type, safe_equals, safe_issubclass, safe_isinstance

T = TypeVar("T")
# __builtin__ in Python 2 and builtins in Python 3
Expand Down Expand Up @@ -432,15 +432,15 @@ def can_assign(self, other: Value, ctx: CanAssignContext) -> CanAssign:
if isinstance(other, KnownValue):
if self.val is other.val:
return {}
if self.val == other.val and type(self.val) is type(other.val):
if safe_equals(self.val, other.val) and type(self.val) is type(other.val):
return {}
return super().can_assign(other, ctx)

def __eq__(self, other: Value) -> bool:
return (
isinstance(other, KnownValue)
and type(self.val) is type(other.val)
and self.val == other.val
and safe_equals(self.val, other.val)
)

def __ne__(self, other: Value) -> bool:
Expand Down

0 comments on commit 39fd292

Please sign in to comment.