77 */
88
99// Importing python under the `py` namespace to avoid importing `CallNode` from `Flow.qll` and thereby having a naming conflict with `API::CallNode`.
10- private import python as py
10+ private import python as PY
1111import semmle.python.dataflow.new.DataFlow
1212private import semmle.python.internal.CachedStages
1313
@@ -428,13 +428,13 @@ module API {
428428 /** An abstract representative for imports of the module called `name`. */
429429 MkModuleImport ( string name ) {
430430 // Ignore the following module name for Python 2, as we alias `__builtin__` to `builtins` elsewhere
431- ( name != "__builtin__" or py :: major_version ( ) = 3 ) and
431+ ( name != "__builtin__" or PY :: major_version ( ) = 3 ) and
432432 (
433433 imports ( _, name )
434434 or
435435 // When we `import foo.bar.baz` we want to create API graph nodes also for the prefixes
436436 // `foo` and `foo.bar`:
437- name = any ( py :: ImportExpr e | not e .isRelative ( ) ) .getAnImportedModuleName ( )
437+ name = any ( PY :: ImportExpr e | not e .isRelative ( ) ) .getAnImportedModuleName ( )
438438 )
439439 or
440440 // The `builtins` module should always be implicitly available
@@ -470,7 +470,7 @@ module API {
470470 * Ignores relative imports, such as `from ..foo.bar import baz`.
471471 */
472472 private predicate imports ( DataFlow:: Node imp , string name ) {
473- exists ( py :: ImportExprNode iexpr |
473+ exists ( PY :: ImportExprNode iexpr |
474474 imp .asCfgNode ( ) = iexpr and
475475 not iexpr .getNode ( ) .isRelative ( ) and
476476 name = iexpr .getNode ( ) .getImportedModuleName ( )
@@ -493,7 +493,7 @@ module API {
493493 *
494494 * `moduleImport("foo").getMember("bar")`
495495 */
496- private TApiNode potential_import_star_base ( py :: Scope s ) {
496+ private TApiNode potential_import_star_base ( PY :: Scope s ) {
497497 exists ( DataFlow:: Node n |
498498 n .asCfgNode ( ) = ImportStar:: potentialImportStarBase ( s ) and
499499 use ( result , n )
@@ -516,17 +516,17 @@ module API {
516516 )
517517 or
518518 // TODO: I had expected `DataFlow::AttrWrite` to contain the attribute writes from a dict, that's how JS works.
519- exists ( py :: Dict dict , py :: KeyValuePair item |
519+ exists ( PY :: Dict dict , PY :: KeyValuePair item |
520520 dict = pred .asExpr ( ) and
521521 dict .getItem ( _) = item and
522- lbl = Label:: member ( item .getKey ( ) .( py :: StrConst ) .getS ( ) ) and
522+ lbl = Label:: member ( item .getKey ( ) .( PY :: StrConst ) .getS ( ) ) and
523523 rhs .asExpr ( ) = item .getValue ( )
524524 )
525525 or
526- exists ( py :: CallableExpr fn | fn = pred .asExpr ( ) |
526+ exists ( PY :: CallableExpr fn | fn = pred .asExpr ( ) |
527527 not fn .getInnerScope ( ) .isAsync ( ) and
528528 lbl = Label:: return ( ) and
529- exists ( py :: Return ret |
529+ exists ( PY :: Return ret |
530530 rhs .asExpr ( ) = ret .getValue ( ) and
531531 ret .getScope ( ) = fn .getInnerScope ( )
532532 )
@@ -569,7 +569,7 @@ module API {
569569 // Subclassing a node
570570 lbl = Label:: subclass ( ) and
571571 exists ( DataFlow:: Node superclass | pred .flowsTo ( superclass ) |
572- ref .asExpr ( ) .( py :: ClassExpr ) .getABase ( ) = superclass .asExpr ( )
572+ ref .asExpr ( ) .( PY :: ClassExpr ) .getABase ( ) = superclass .asExpr ( )
573573 )
574574 or
575575 // awaiting
@@ -580,7 +580,7 @@ module API {
580580 )
581581 )
582582 or
583- exists ( DataFlow:: Node def , py :: CallableExpr fn |
583+ exists ( DataFlow:: Node def , PY :: CallableExpr fn |
584584 rhs ( base , def ) and fn = trackDefNode ( def ) .asExpr ( )
585585 |
586586 exists ( int i |
@@ -599,7 +599,7 @@ module API {
599599 lbl = Label:: member ( any ( string name | ref = Builtins:: likelyBuiltin ( name ) ) )
600600 or
601601 // Unknown variables that may belong to a module imported with `import *`
602- exists ( py :: Scope s |
602+ exists ( PY :: Scope s |
603603 base = potential_import_star_base ( s ) and
604604 lbl =
605605 Label:: member ( any ( string name |
@@ -619,7 +619,7 @@ module API {
619619 )
620620 or
621621 // Ensure the Python 2 `__builtin__` module gets the name of the Python 3 `builtins` module.
622- py :: major_version ( ) = 2 and
622+ PY :: major_version ( ) = 2 and
623623 nd = MkModuleImport ( "builtins" ) and
624624 imports ( ref , "__builtin__" )
625625 or
@@ -761,18 +761,18 @@ module API {
761761 exists ( Builtins:: likelyBuiltin ( member ) ) or
762762 ImportStar:: namePossiblyDefinedInImportStar ( _, member , _) or
763763 Impl:: prefix_member ( _, member , _) or
764- member = any ( py :: Dict d ) .getAnItem ( ) .( py :: KeyValuePair ) .getKey ( ) .( py :: StrConst ) .getS ( )
764+ member = any ( PY :: Dict d ) .getAnItem ( ) .( PY :: KeyValuePair ) .getKey ( ) .( PY :: StrConst ) .getS ( )
765765 } or
766766 MkLabelUnknownMember ( ) or
767767 MkLabelParameter ( int i ) {
768768 exists ( any ( DataFlow:: CallCfgNode c ) .getArg ( i ) )
769769 or
770- exists ( any ( py :: Function f ) .getArg ( i ) )
770+ exists ( any ( PY :: Function f ) .getArg ( i ) )
771771 } or
772772 MkLabelKeywordParameter ( string name ) {
773773 exists ( any ( DataFlow:: CallCfgNode c ) .getArgByName ( name ) )
774774 or
775- exists ( any ( py :: Function f ) .getArgByName ( name ) )
775+ exists ( any ( PY :: Function f ) .getArgByName ( name ) )
776776 } or
777777 MkLabelReturn ( ) or
778778 MkLabelSubclass ( ) or
0 commit comments