Skip to content

Commit 890ef25

Browse files
committed
fixed orjson dumps bytes bug
1 parent 2732bdc commit 890ef25

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

codetide/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def serialize(self,
142142

143143
if include_cached_ids:
144144
cached_ids_path = dir_path / DEFAULT_CACHED_IDS_FILE
145-
writeFile(str(orjson.dumps(self.cached_ids, option=orjson.OPT_INDENT_2)), cached_ids_path)
145+
writeFile(orjson.dumps(self.cached_ids, option=orjson.OPT_INDENT_2), cached_ids_path)
146146

147147
@classmethod
148148
def deserialize(cls, filepath :Optional[Union[str, Path]]=DEFAULT_SERIALIZATION_PATH, rootpath :Optional[Union[str, Path]] = None)->"CodeTide":

codetide/core/common.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ def readFile(path :Union[str, Path], mode :str="r")->str:
77
contents = _file.read()
88
return contents
99

10-
def writeFile(contents :str, path :Union[str, Path], mode :str="w"):
11-
with open(path, mode, encoding=DEFAULT_ENCODING) as _file:
12-
_file.write(contents)
10+
def writeFile(contents: Union[str, bytes], path: Union[str, Path], mode: str = "w"):
11+
if isinstance(contents, bytes):
12+
with open(path, "wb") as f:
13+
f.write(contents)
14+
else:
15+
with open(path, mode, encoding=DEFAULT_ENCODING) as f:
16+
f.write(contents)
1317

1418
def wrap_package_dependencies(content: str) -> str:
1519
return f"""<PACKAGE_DEPENDENCIES_START>

0 commit comments

Comments
 (0)