Skip to content

Commit cc58f01

Browse files
cleanup
1 parent d717554 commit cc58f01

4 files changed

Lines changed: 15 additions & 11 deletions

File tree

packages/reflex-base/src/reflex_base/utils/format.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -685,8 +685,9 @@ def orjson_dumps(obj: Any, **kwargs) -> str:
685685
"""Serialize obj to a JSON string, using orjson when available.
686686
687687
Translates common json.dumps kwargs (indent, sort_keys) into orjson
688-
option flags. Falls back to stdlib json if orjson is not installed,
689-
an unsupported kwarg is passed, or orjson raises TypeError.
688+
option flags. Falls back to ``json_dumps`` (which has the
689+
``serializers.serialize`` default) if orjson is not installed, an
690+
unsupported kwarg is passed, or orjson raises TypeError.
690691
691692
Args:
692693
obj: The object to serialize.
@@ -698,7 +699,7 @@ def orjson_dumps(obj: Any, **kwargs) -> str:
698699
try:
699700
import orjson # pyright: ignore[reportMissingImports]
700701
except ImportError:
701-
return json.dumps(obj, **kwargs)
702+
return json_dumps(obj, **kwargs)
702703

703704
option = 0
704705
if kwargs.pop("indent", None):
@@ -709,13 +710,14 @@ def orjson_dumps(obj: Any, **kwargs) -> str:
709710

710711
if kwargs:
711712
# Fall back to stdlib json for unsupported kwargs.
712-
return json.dumps(obj, **kwargs)
713+
return json_dumps(obj, **kwargs)
713714

714715
try:
715716
return orjson.dumps(obj, option=option or None).decode()
716717
except TypeError:
717-
# Fallback for types orjson can't handle (e.g. int > 64-bit).
718-
return json.dumps(obj)
718+
# Fallback for types orjson can't handle (e.g. int > 64-bit, or
719+
# custom types). ``json_dumps`` carries the serializer default.
720+
return json_dumps(obj)
719721

720722

721723
def orjson_loads(data: str | bytes) -> Any:

packages/reflex-base/src/reflex_base/utils/pyi_generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1763,7 +1763,7 @@ def scan_all(
17631763

17641764
pyi_hashes_file = pyi_hashes_parent / PYI_HASHES
17651765
if pyi_hashes_file.exists():
1766-
pyi_hashes = orjson_loads(pyi_hashes_file.read_text())
1766+
pyi_hashes = orjson_loads(pyi_hashes_file.read_bytes())
17671767
for file_path, hashed_content in zip(
17681768
file_paths, hashes, strict=False
17691769
):

reflex/utils/prerequisites.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def get_or_set_last_reflex_version_check_datetime():
113113
if not reflex_json_file.exists():
114114
return None
115115
# Open and read the file
116-
data = orjson_loads(reflex_json_file.read_text())
116+
data = orjson_loads(reflex_json_file.read_bytes())
117117
last_version_check_datetime = data.get("last_version_check_datetime")
118118
if not last_version_check_datetime:
119119
data.update({"last_version_check_datetime": str(datetime.now())})
@@ -496,7 +496,7 @@ def get_project_hash(raise_on_fail: bool = False) -> int | None:
496496
json_file = get_web_dir() / constants.Reflex.JSON
497497
if not json_file.exists() and not raise_on_fail:
498498
return None
499-
data = orjson_loads(json_file.read_text())
499+
data = orjson_loads(json_file.read_bytes())
500500
return data.get("project_hash")
501501

502502

@@ -566,7 +566,7 @@ def _is_app_compiled_with_same_reflex_version() -> bool:
566566
json_file = get_web_dir() / constants.Reflex.JSON
567567
if not json_file.exists():
568568
return False
569-
app_version = orjson_loads(json_file.read_text()).get("version")
569+
app_version = orjson_loads(json_file.read_bytes()).get("version")
570570
return app_version == constants.Reflex.VERSION
571571

572572

reflex/utils/telemetry.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ def get_cpu_info() -> CpuInfo | None:
111111
The CPU info.
112112
"""
113113
cpu_info_file = environment.REFLEX_DIR.get() / "cpu_info.json"
114-
if cpu_info_file.exists() and (cpu_info := orjson_loads(cpu_info_file.read_text())):
114+
if cpu_info_file.exists() and (
115+
cpu_info := orjson_loads(cpu_info_file.read_bytes())
116+
):
115117
return CpuInfo(**cpu_info)
116118
cpu_info = _retrieve_cpu_info()
117119
if cpu_info:

0 commit comments

Comments
 (0)