Added negative numbers support to the document macro.

This commit is contained in:
Salvador E. Tropea 2020-06-25 08:09:39 -03:00
parent 6295b00657
commit fb5c32f0ad
1 changed files with 4 additions and 1 deletions

View File

@ -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):