File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed
python/ql/src/semmle/python Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -89,7 +89,15 @@ class File extends Container {
8989 i .getTest ( ) .( Compare ) .compares ( name , op , main ) and
9090 name .getId ( ) = "__name__" and
9191 main .getText ( ) = "__main__"
92- )
92+ ) and
93+ // Exclude files named `__main__.py`. These are often _not_ meant to be run directly, but
94+ // contain this construct anyway.
95+ //
96+ // Their presence in a package (say, `foo`) means one can execute the package directly using
97+ // `python -m foo` (which will run the `foo/__main__.py` file). Since being an entry point for
98+ // execution means treating imports as absolute, this causes trouble, since when run with
99+ // `python -m`, the interpreter uses the usual package semantics.
100+ not this .getShortName ( ) = "__main__.py"
93101 or
94102 // The file contains a `#!` line referencing the python interpreter
95103 exists ( Comment c |
You can’t perform that action at this time.
0 commit comments