@@ -42,11 +42,25 @@ predicate mutates_globals(ModuleValue m) {
4242 )
4343}
4444
45+ predicate is_exported_submodule_name ( ModuleValue m , string exported_name ) {
46+ m .getScope ( ) .getShortName ( ) = "__init__" and
47+ exists ( m .getScope ( ) .getPackage ( ) .getSubModule ( exported_name ) )
48+ }
49+
50+ predicate contains_unknown_import_star ( ModuleValue m ) {
51+ exists ( ImportStarNode imp | imp .getEnclosingModule ( ) = m .getScope ( ) |
52+ imp .getModule ( ) .pointsTo ( ) .isAbsent ( )
53+ or
54+ not exists ( imp .getModule ( ) .pointsTo ( ) )
55+ )
56+ }
57+
4558from ModuleValue m , StrConst name , string exported_name
46- where declaredInAll ( m .getScope ( ) , name ) and
47- exported_name = name .strValue ( ) and
48- not m .hasAttribute ( exported_name ) and
49- not ( m .getScope ( ) .getShortName ( ) = "__init__" and exists ( m .getScope ( ) .getPackage ( ) .getSubModule ( exported_name ) ) ) and
50- not exists ( ImportStarNode imp | imp .getEnclosingModule ( ) = m .getScope ( ) | imp .getModule ( ) .pointsTo ( ) .isAbsent ( ) ) and
51- not mutates_globals ( m )
52- select name , "The name '" + exported_name + "' is exported by __all__ but is not defined."
59+ where
60+ declaredInAll ( m .getScope ( ) , name ) and
61+ exported_name = name .strValue ( ) and
62+ not m .hasAttribute ( exported_name ) and
63+ not is_exported_submodule_name ( m , exported_name ) and
64+ not contains_unknown_import_star ( m ) and
65+ not mutates_globals ( m )
66+ select name , "The name '" + exported_name + "' is exported by __all__ but is not defined."
0 commit comments