Python: Don't report Python 2 print statements as having no effect.

This commit is contained in:
Mark Shannon
2019-03-13 10:08:07 +00:00
parent 13c6f55a2e
commit e9a45268a8
2 changed files with 14 additions and 1 deletions

View File

@@ -95,6 +95,14 @@ predicate in_raises_test(Expr e) {
)
}
/** Holds if expression has the form of a Python 2 `print >> out, ...` statement */
predicate python2_print(Expr e) {
e.(BinaryExpr).getLeft().(Name).getId() = "print" and
e.(BinaryExpr).getOp() instanceof RShift
or
python2_print(e.(Tuple).getElt(0))
}
predicate no_effect(Expr e) {
not e instanceof StrConst and
not ((StrConst)e).isDocString() and
@@ -107,7 +115,8 @@ predicate no_effect(Expr e) {
not maybe_side_effecting_attribute(sub)
) and
not in_notebook(e) and
not in_raises_test(e)
not in_raises_test(e) and
not python2_print(e)
}
from ExprStmt stmt

View File

@@ -133,3 +133,7 @@ def do_action(action):
stop()
else:
raise ValueError(action)
#Python 2 print
print >> out, message