From fb5c32f0ad0ea96c23d6f321d048ce0b82630a48 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Thu, 25 Jun 2020 08:09:39 -0300 Subject: [PATCH] Added negative numbers support to the document macro. --- kiplot/macros.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kiplot/macros.py b/kiplot/macros.py index 4baf01d1..a0b0acb2 100644 --- a/kiplot/macros.py +++ b/kiplot/macros.py @@ -1,4 +1,4 @@ -from ast import (Assign, Name, Attribute, Expr, Num, Str, NameConstant, Load, Store) +from ast import (Assign, Name, Attribute, Expr, Num, Str, NameConstant, Load, Store, UnaryOp, USub) def document(sentences, to_source, **kw): @@ -39,6 +39,9 @@ def document(sentences, to_source, **kw): type_hint = '' if isinstance(value, Num): type_hint = '[number={}]'.format(value.n) + elif isinstance(value, UnaryOp) and isinstance(value.operand, Num) and isinstance(value.op, USub): + # -Num + type_hint = '[number={}]'.format(-value.operand.n) elif isinstance(value, Str): type_hint = "[string='{}']".format(value.s) elif isinstance(value, NameConstant) and isinstance(value.value, bool):