Skip to content

Commit 6e4aba8

Browse files
fix(reactive): fix the support of ndarray
1 parent 6161311 commit 6e4aba8

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/reactivity/reactive/__init__.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -587,11 +587,16 @@ def __create_proxy(instance: object):
587587
if DEV:
588588
print(f'[Reactive] create proxy: {instance}')
589589
patched_class = get_patched_class(instance)
590-
proxy = patched_class()
591-
if isinstance(instance, dict):
592-
# NOTE: 根据测试,在 JSONEncoder 中,在对 dict 调用 c_make_encoder 编码时,
593-
# 如果这里不随便填上点儿东西初始化,json.dumps 输出内容会为空 {}
594-
cast(Any, dict).__init__(proxy, {None: None})
590+
try:
591+
proxy = patched_class()
592+
if isinstance(instance, dict):
593+
# NOTE: According to testing, in the JSONEncoder, when calling c_make_encoder to encode a dict,
594+
# if something is not initialized here casually, the output of json.dumps will be an empty {}.
595+
cast(Any, dict).__init__(proxy, {None: None})
596+
except Exception:
597+
# If the class supports passing in an instance of itself and directly returning it, then use this feature to bypass the __new__ method。
598+
# Because we don't know what parameters to fill in for __new__, we can only try to directly pass in an instance of itself.
599+
proxy = patched_class(instance)
595600
return record_new_reactive_obj(cast(object, instance), proxy)
596601

597602

0 commit comments

Comments
 (0)