Added negative numbers support to the document macro.
This commit is contained in:
parent
6295b00657
commit
fb5c32f0ad
|
|
@ -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):
|
def document(sentences, to_source, **kw):
|
||||||
|
|
@ -39,6 +39,9 @@ def document(sentences, to_source, **kw):
|
||||||
type_hint = ''
|
type_hint = ''
|
||||||
if isinstance(value, Num):
|
if isinstance(value, Num):
|
||||||
type_hint = '[number={}]'.format(value.n)
|
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):
|
elif isinstance(value, Str):
|
||||||
type_hint = "[string='{}']".format(value.s)
|
type_hint = "[string='{}']".format(value.s)
|
||||||
elif isinstance(value, NameConstant) and isinstance(value.value, bool):
|
elif isinstance(value, NameConstant) and isinstance(value.value, bool):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue