[BUGFIX] If(): test_comment bool convert; skip handling after return; do not echo constants.
This commit is contained in:
parent
675b112a16
commit
963a65fa71
@ -9,7 +9,6 @@ def test_constant():
|
||||
|
||||
asserteq_or_print(target(), '''
|
||||
def target():
|
||||
1
|
||||
''')
|
||||
|
||||
|
||||
|
||||
@ -36,8 +36,8 @@ class Commentor(object):
|
||||
with open(inspect.getfile(func)) as f:
|
||||
all_lines = f.readlines()
|
||||
other_lines = dict(
|
||||
before="".join(all_lines[:start_lineno-1]),
|
||||
after="".join(all_lines[start_lineno+len(raw_lines):])
|
||||
before="".join(all_lines[:start_lineno-1]) + "\n",
|
||||
after="\n" + "".join(all_lines[start_lineno+len(raw_lines):])
|
||||
)
|
||||
self.indent = len(raw_lines[0]) - len(raw_lines[0].lstrip())
|
||||
unindented_source = ''.join([l[self.indent:] for l in raw_lines])
|
||||
|
||||
@ -14,11 +14,12 @@ NORMAL = 0
|
||||
BREAK = 8
|
||||
CONTINUE = 16
|
||||
RAISE = 32
|
||||
RETURN = 64
|
||||
|
||||
REG = lambda i: f"__REG{i}"
|
||||
|
||||
APPEND_SOURCE_BY_THEMSELVES = [
|
||||
ast.If, ast.For, ast.With
|
||||
ast.If, ast.For, ast.With, ast.Expr
|
||||
]
|
||||
|
||||
ASSIGN_SILENT = [
|
||||
|
||||
@ -11,7 +11,7 @@ def If(self, cmtor, state=0):
|
||||
test = False
|
||||
test_comment = "skipped"
|
||||
else:
|
||||
test = cmtor.eval(self.test, format=False)
|
||||
test = bool(cmtor.eval(self.test, format=False))
|
||||
test_comment = test
|
||||
if test:
|
||||
state = state | PASS
|
||||
|
||||
@ -25,6 +25,7 @@ def FunctionDef(self, cmtor):
|
||||
def Return(self, cmtor):
|
||||
cmtor.process(self.value)
|
||||
cmtor._return = cmtor.eval(self.value, format=False)
|
||||
cmtor._stack_event = flags.RETURN
|
||||
|
||||
|
||||
def Lambda(self, cmtor):
|
||||
|
||||
@ -2,7 +2,9 @@ from ..utils import *
|
||||
|
||||
|
||||
def Expr(self, cmtor):
|
||||
cmtor.process(self.value)
|
||||
if type(self.value) != ast.Constant:
|
||||
cmtor.append_source(cmtor.to_source(self))
|
||||
cmtor.process(self.value)
|
||||
|
||||
|
||||
def UnaryOp(self, cmtor):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user