@@ -141,7 +141,7 @@ module PointsTo {
141141 )
142142 or
143143 not f .isParameter ( ) and
144- exists ( Value value |
144+ exists ( ObjectInternal value |
145145 PointsToInternal:: pointsTo ( f .( DefinitionNode ) .getValue ( ) , context , value , origin ) and
146146 cls = value .getClass ( ) .getSource ( ) |
147147 obj = value .getSource ( ) or
@@ -151,7 +151,7 @@ module PointsTo {
151151
152152 deprecated predicate
153153 ssa_variable_points_to ( EssaVariable var , PointsToContext context , Object obj , ClassObject cls , CfgOrigin origin ) {
154- exists ( Value value |
154+ exists ( ObjectInternal value |
155155 PointsToInternal:: variablePointsTo ( var , context , value , origin ) and
156156 cls = value .getClass ( ) .getSource ( ) |
157157 obj = value .getSource ( )
@@ -160,8 +160,8 @@ module PointsTo {
160160
161161 deprecated
162162 CallNode get_a_call ( Object func , PointsToContext context ) {
163- exists ( Value value |
164- result = value .getACall ( context ) and
163+ exists ( ObjectInternal value |
164+ result = value .( Value ) . getACall ( context ) and
165165 func = value .getSource ( )
166166 )
167167 }
@@ -402,7 +402,7 @@ cached module PointsToInternal {
402402 or
403403 scope_entry_points_to ( def , context , value , origin )
404404 or
405- InterModulePointsTo:: implicit_submodule_points_to ( def , context , value , origin )
405+ InterModulePointsTo:: implicit_submodule_points_to ( def , value , origin ) and context . isImport ( )
406406 or
407407 iteration_definition_points_to ( def , context , value , origin )
408408 /*
@@ -647,18 +647,22 @@ private module InterModulePointsTo {
647647 )
648648 }
649649
650+ /* Helper for implicit_submodule_points_to */
651+ private ModuleObjectInternal getModule ( ImplicitSubModuleDefinition def ) {
652+ exists ( PackageObjectInternal package |
653+ package .getSourceModule ( ) = def .getDefiningNode ( ) .getScope ( ) and
654+ result = package .submodule ( def .getSourceVariable ( ) .getName ( ) )
655+ )
656+ }
657+
650658 /** Implicit "definition" of the names of submodules at the start of an `__init__.py` file.
651659 *
652660 * PointsTo isn't exactly how the interpreter works, but is the best approximation we can manage statically.
653661 */
654662 pragma [ noinline]
655- predicate implicit_submodule_points_to ( ImplicitSubModuleDefinition def , PointsToContext context , ModuleObjectInternal value , ControlFlowNode origin ) {
656- exists ( PackageObjectInternal package |
657- package .getSourceModule ( ) = def .getDefiningNode ( ) .getScope ( ) |
658- value = package .submodule ( def .getSourceVariable ( ) .getName ( ) ) and
659- origin = CfgOrigin:: fromObject ( value ) .asCfgNodeOrHere ( def .getDefiningNode ( ) ) and
660- context .isImport ( )
661- )
663+ predicate implicit_submodule_points_to ( ImplicitSubModuleDefinition def , ModuleObjectInternal value , ControlFlowNode origin ) {
664+ value = getModule ( def ) and
665+ origin = CfgOrigin:: fromObject ( value ) .asCfgNodeOrHere ( def .getDefiningNode ( ) )
662666 }
663667
664668 /** Points-to for `from ... import *`. */
@@ -1869,9 +1873,13 @@ cached module Types {
18691873 result = getInheritedMetaclass ( cls , 0 )
18701874 or
18711875 // Best guess if base is not a known class
1876+ hasUnknownBase ( cls ) and result = ObjectInternal:: unknownClass ( )
1877+ }
1878+
1879+ /* Helper for getInheritedMetaclass */
1880+ private predicate hasUnknownBase ( ClassObjectInternal cls ) {
18721881 exists ( ObjectInternal base |
1873- base = getBase ( cls , _) and
1874- result = ObjectInternal:: unknownClass ( ) |
1882+ base = getBase ( cls , _) |
18751883 base .isClass ( ) = false
18761884 or
18771885 base = ObjectInternal:: unknownClass ( )
@@ -1881,14 +1889,18 @@ cached module Types {
18811889 private ClassObjectInternal getInheritedMetaclass ( ClassObjectInternal cls , int n ) {
18821890 exists ( Class c |
18831891 c = cls .( PythonClassObjectInternal ) .getScope ( ) and
1884- n = count ( c .getABase ( ) )
1892+ n = count ( c .getABase ( ) ) and n != 1
18851893 |
18861894 result = ObjectInternal:: type ( ) and major_version ( ) = 3
18871895 or
18881896 result = ObjectInternal:: classType ( ) and major_version ( ) = 2
18891897 )
18901898 or
1899+ base_count ( cls ) = 1 and n = 0 and
1900+ result = getBase ( cls , 0 ) .getClass ( )
1901+ or
18911902 exists ( ClassObjectInternal meta1 , ClassObjectInternal meta2 |
1903+ base_count ( cls ) > 1 and
18921904 meta1 = getBase ( cls , n ) .getClass ( ) and
18931905 meta2 = getInheritedMetaclass ( cls , n + 1 )
18941906 |
0 commit comments