From f859ffb3e2f02e54c8160d01b23c1d27600f6f6f Mon Sep 17 00:00:00 2001 From: Fumito Hamamura Date: Sat, 5 Oct 2024 21:03:50 +0900 Subject: [PATCH] FIX: Serialize unary op --- modelx/serialize/serializer_6.py | 5 ++++- modelx/tests/serialize/test_primitive_types.py | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/modelx/serialize/serializer_6.py b/modelx/serialize/serializer_6.py index e11ffe6..d41e2d3 100644 --- a/modelx/serialize/serializer_6.py +++ b/modelx/serialize/serializer_6.py @@ -1493,7 +1493,10 @@ def condition(cls, node): return True def decode(self): - valstr = self.node.first_token.string.strip() + if isinstance(self.node, ast.UnaryOp): # such as -1 + valstr = self.node.first_token.string.strip() + self.node.last_token.string.strip() + else: + valstr = self.node.first_token.string.strip() if valstr in ["True", "False", "None"]: return ast.literal_eval(self.node) else: diff --git a/modelx/tests/serialize/test_primitive_types.py b/modelx/tests/serialize/test_primitive_types.py index 02aeea4..bdce458 100644 --- a/modelx/tests/serialize/test_primitive_types.py +++ b/modelx/tests/serialize/test_primitive_types.py @@ -9,7 +9,8 @@ ('b', False, 'False'), ('c', None, 'None'), ('d', np.inf, 'Infinity'), - ('e', np.pi, '3.141592653589793') + ('e', np.pi, '3.141592653589793'), + ('f', -1, '-1') ]