File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed
Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change 1212 */
1313
1414import python
15- private import LegacyPointsTo
1615
1716predicate main_eq_name ( If i ) {
1817 exists ( Name n , StringLiteral m , Compare c |
@@ -32,10 +31,19 @@ predicate is_print_stmt(Stmt s) {
3231 )
3332}
3433
34+ /**
35+ * Holds if module `m` is likely used as a module (imported by another module),
36+ * as opposed to being exclusively used as a script.
37+ */
38+ predicate is_used_as_module ( Module m ) {
39+ m .isPackageInit ( )
40+ or
41+ exists ( ImportingStmt i | i .getAnImportedModuleName ( ) = m .getName ( ) )
42+ }
43+
3544from Stmt p
3645where
3746 is_print_stmt ( p ) and
38- // TODO: Need to discuss how we would like to handle ModuleObject.getKind in the glorious future
39- exists ( ModuleValue m | m .getScope ( ) = p .getScope ( ) and m .isUsedAsModule ( ) ) and
47+ is_used_as_module ( p .getScope ( ) .( Module ) ) and
4048 not exists ( If i | main_eq_name ( i ) and i .getASubStatement ( ) .getASubStatement * ( ) = p )
4149select p , "Print statement may execute during import."
You can’t perform that action at this time.
0 commit comments