Skip to content

Commit

Permalink
FIX: Serialize unary op
Browse files Browse the repository at this point in the history
  • Loading branch information
fumitoh committed Oct 5, 2024
1 parent 1dd92c7 commit f859ffb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion modelx/serialize/serializer_6.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion modelx/tests/serialize/test_primitive_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
]


Expand Down

0 comments on commit f859ffb

Please sign in to comment.