diff --git a/src/reactpy/core/hooks.py b/src/reactpy/core/hooks.py index 0ece8cccf..381abe71e 100644 --- a/src/reactpy/core/hooks.py +++ b/src/reactpy/core/hooks.py @@ -1,6 +1,7 @@ from __future__ import annotations import asyncio +import contextlib from collections.abc import Coroutine, MutableMapping, Sequence from logging import getLogger from types import FunctionType @@ -517,18 +518,11 @@ def strictly_equal(x: Any, y: Any) -> bool: - ``bytearray`` - ``memoryview`` """ - return x is y or (type(x) in _NUMERIC_TEXT_BINARY_TYPES and x == y) - - -_NUMERIC_TEXT_BINARY_TYPES = { - # numeric - int, - float, - complex, - # text - str, - # binary types - bytes, - bytearray, - memoryview, -} + if type(x) is not type(y): + return False + + with contextlib.suppress(Exception): + if hasattr(x, "__eq__"): + return x == y + + return x is y diff --git a/tests/test_core/test_hooks.py b/tests/test_core/test_hooks.py index 550d35cbc..6d7162bed 100644 --- a/tests/test_core/test_hooks.py +++ b/tests/test_core/test_hooks.py @@ -159,7 +159,7 @@ def Counter(): await layout.render() -async def test_set_state_checks_identity_not_equality(display: DisplayFixture): +async def test_set_state_checks_equality_not_identity(display: DisplayFixture): r_1 = reactpy.Ref("value") r_2 = reactpy.Ref("value") @@ -219,12 +219,12 @@ def TestComponent(): await client_r_2_button.click() await poll_event_count.until_equals(2) - await poll_render_count.until_equals(2) + await poll_render_count.until_equals(1) await client_r_2_button.click() await poll_event_count.until_equals(3) - await poll_render_count.until_equals(2) + await poll_render_count.until_equals(1) async def test_simple_input_with_use_state(display: DisplayFixture):