Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.

Commit d3b389e

Browse files
authored
Merge pull request #89 from juanjux/fix/complex_serialize
Fixed complex numbers json serialization
2 parents b9e2cd2 + ab14f74 commit d3b389e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Diff for: native/python_package/python_driver/astimprove.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -499,11 +499,17 @@ def visit_NameConstant(self, node):
499499
node["ast_type"] = "NameConstant"
500500
return node
501501

502+
def visit_Num(self, node):
503+
# complex objects are not json-serializable
504+
if isinstance(node["n"], complex):
505+
node.update({"n": {"real": node["n"].real,
506+
"imag": node["n"].imag}})
507+
return node
508+
502509
def visit_other(self, node):
503510
for field in node.get("_fields", []):
504511
meth = getattr(self, "visit_" + node["ast_type"], self.visit_other_field)
505512
node[field] = meth(node[field])
506-
507513
return node
508514

509515
def visit_other_field(self, node):

0 commit comments

Comments
 (0)