7
7
*/
8
8
9
9
// 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
11
11
import semmle.python.dataflow.new.DataFlow
12
12
private import semmle.python.internal.CachedStages
13
13
@@ -428,13 +428,13 @@ module API {
428
428
/** An abstract representative for imports of the module called `name`. */
429
429
MkModuleImport ( string name ) {
430
430
// 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
432
432
(
433
433
imports ( _, name )
434
434
or
435
435
// When we `import foo.bar.baz` we want to create API graph nodes also for the prefixes
436
436
// `foo` and `foo.bar`:
437
- name = any ( py :: ImportExpr e | not e .isRelative ( ) ) .getAnImportedModuleName ( )
437
+ name = any ( PY :: ImportExpr e | not e .isRelative ( ) ) .getAnImportedModuleName ( )
438
438
)
439
439
or
440
440
// The `builtins` module should always be implicitly available
@@ -470,7 +470,7 @@ module API {
470
470
* Ignores relative imports, such as `from ..foo.bar import baz`.
471
471
*/
472
472
private predicate imports ( DataFlow:: Node imp , string name ) {
473
- exists ( py :: ImportExprNode iexpr |
473
+ exists ( PY :: ImportExprNode iexpr |
474
474
imp .asCfgNode ( ) = iexpr and
475
475
not iexpr .getNode ( ) .isRelative ( ) and
476
476
name = iexpr .getNode ( ) .getImportedModuleName ( )
@@ -493,7 +493,7 @@ module API {
493
493
*
494
494
* `moduleImport("foo").getMember("bar")`
495
495
*/
496
- private TApiNode potential_import_star_base ( py :: Scope s ) {
496
+ private TApiNode potential_import_star_base ( PY :: Scope s ) {
497
497
exists ( DataFlow:: Node n |
498
498
n .asCfgNode ( ) = ImportStar:: potentialImportStarBase ( s ) and
499
499
use ( result , n )
@@ -516,17 +516,17 @@ module API {
516
516
)
517
517
or
518
518
// 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 |
520
520
dict = pred .asExpr ( ) and
521
521
dict .getItem ( _) = item and
522
- lbl = Label:: member ( item .getKey ( ) .( py :: StrConst ) .getS ( ) ) and
522
+ lbl = Label:: member ( item .getKey ( ) .( PY :: StrConst ) .getS ( ) ) and
523
523
rhs .asExpr ( ) = item .getValue ( )
524
524
)
525
525
or
526
- exists ( py :: CallableExpr fn | fn = pred .asExpr ( ) |
526
+ exists ( PY :: CallableExpr fn | fn = pred .asExpr ( ) |
527
527
not fn .getInnerScope ( ) .isAsync ( ) and
528
528
lbl = Label:: return ( ) and
529
- exists ( py :: Return ret |
529
+ exists ( PY :: Return ret |
530
530
rhs .asExpr ( ) = ret .getValue ( ) and
531
531
ret .getScope ( ) = fn .getInnerScope ( )
532
532
)
@@ -569,7 +569,7 @@ module API {
569
569
// Subclassing a node
570
570
lbl = Label:: subclass ( ) and
571
571
exists ( DataFlow:: Node superclass | pred .flowsTo ( superclass ) |
572
- ref .asExpr ( ) .( py :: ClassExpr ) .getABase ( ) = superclass .asExpr ( )
572
+ ref .asExpr ( ) .( PY :: ClassExpr ) .getABase ( ) = superclass .asExpr ( )
573
573
)
574
574
or
575
575
// awaiting
@@ -580,7 +580,7 @@ module API {
580
580
)
581
581
)
582
582
or
583
- exists ( DataFlow:: Node def , py :: CallableExpr fn |
583
+ exists ( DataFlow:: Node def , PY :: CallableExpr fn |
584
584
rhs ( base , def ) and fn = trackDefNode ( def ) .asExpr ( )
585
585
|
586
586
exists ( int i |
@@ -599,7 +599,7 @@ module API {
599
599
lbl = Label:: member ( any ( string name | ref = Builtins:: likelyBuiltin ( name ) ) )
600
600
or
601
601
// Unknown variables that may belong to a module imported with `import *`
602
- exists ( py :: Scope s |
602
+ exists ( PY :: Scope s |
603
603
base = potential_import_star_base ( s ) and
604
604
lbl =
605
605
Label:: member ( any ( string name |
@@ -619,7 +619,7 @@ module API {
619
619
)
620
620
or
621
621
// 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
623
623
nd = MkModuleImport ( "builtins" ) and
624
624
imports ( ref , "__builtin__" )
625
625
or
@@ -761,18 +761,18 @@ module API {
761
761
exists ( Builtins:: likelyBuiltin ( member ) ) or
762
762
ImportStar:: namePossiblyDefinedInImportStar ( _, member , _) or
763
763
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 ( )
765
765
} or
766
766
MkLabelUnknownMember ( ) or
767
767
MkLabelParameter ( int i ) {
768
768
exists ( any ( DataFlow:: CallCfgNode c ) .getArg ( i ) )
769
769
or
770
- exists ( any ( py :: Function f ) .getArg ( i ) )
770
+ exists ( any ( PY :: Function f ) .getArg ( i ) )
771
771
} or
772
772
MkLabelKeywordParameter ( string name ) {
773
773
exists ( any ( DataFlow:: CallCfgNode c ) .getArgByName ( name ) )
774
774
or
775
- exists ( any ( py :: Function f ) .getArgByName ( name ) )
775
+ exists ( any ( PY :: Function f ) .getArgByName ( name ) )
776
776
} or
777
777
MkLabelReturn ( ) or
778
778
MkLabelSubclass ( ) or
0 commit comments