Skip to content

Commit 618f89c

Browse files
committed
Change set_state comparison method
1 parent 754dc11 commit 618f89c

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

src/reactpy/core/hooks.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import asyncio
4+
import contextlib
45
from collections.abc import Coroutine, MutableMapping, Sequence
56
from logging import getLogger
67
from types import FunctionType
@@ -517,18 +518,11 @@ def strictly_equal(x: Any, y: Any) -> bool:
517518
- ``bytearray``
518519
- ``memoryview``
519520
"""
520-
return x is y or (type(x) in _NUMERIC_TEXT_BINARY_TYPES and x == y)
521-
522-
523-
_NUMERIC_TEXT_BINARY_TYPES = {
524-
# numeric
525-
int,
526-
float,
527-
complex,
528-
# text
529-
str,
530-
# binary types
531-
bytes,
532-
bytearray,
533-
memoryview,
534-
}
521+
if type(x) is not type(y):
522+
return False
523+
524+
with contextlib.suppress(Exception):
525+
if hasattr(x, "__eq__"):
526+
return x == y
527+
528+
return x is y

tests/test_core/test_hooks.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def Counter():
159159
await layout.render()
160160

161161

162-
async def test_set_state_checks_identity_not_equality(display: DisplayFixture):
162+
async def test_set_state_checks_equality_not_identity(display: DisplayFixture):
163163
r_1 = reactpy.Ref("value")
164164
r_2 = reactpy.Ref("value")
165165

@@ -219,12 +219,12 @@ def TestComponent():
219219
await client_r_2_button.click()
220220

221221
await poll_event_count.until_equals(2)
222-
await poll_render_count.until_equals(2)
222+
await poll_render_count.until_equals(1)
223223

224224
await client_r_2_button.click()
225225

226226
await poll_event_count.until_equals(3)
227-
await poll_render_count.until_equals(2)
227+
await poll_render_count.until_equals(1)
228228

229229

230230
async def test_simple_input_with_use_state(display: DisplayFixture):

0 commit comments

Comments
 (0)