diff --git a/docs/changelog.md b/docs/changelog.md index 459a346c..971d7bdb 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -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) diff --git a/pyanalyze/value.py b/pyanalyze/value.py index fd7a20a0..9b756e81 100644 --- a/pyanalyze/value.py +++ b/pyanalyze/value.py @@ -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 @@ -432,7 +432,7 @@ 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) @@ -440,7 +440,7 @@ 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: