Skip to content

Commit

Permalink
Change set_state comparison method
Browse files Browse the repository at this point in the history
  • Loading branch information
Archmonger committed Jan 26, 2025
1 parent 754dc11 commit 618f89c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
24 changes: 9 additions & 15 deletions src/reactpy/core/hooks.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
6 changes: 3 additions & 3 deletions tests/test_core/test_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 618f89c

Please sign in to comment.