Skip to content

Commit 93e3566

Browse files
committed
Python: Make isNewType more precise
For module-level metaclass declarations, we now also check that the right hand side in a `__metaclass__ = type` assignment is in fact the built-in `type`.
1 parent a276f72 commit 93e3566

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

python/ql/lib/semmle/python/dataflow/new/internal/DataFlowDispatch.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2108,7 +2108,8 @@ module DuckTyping {
21082108
// Module-level __metaclass__ = type makes all classes in the module new-style
21092109
exists(Assign a |
21102110
a.getScope() = cls.getEnclosingModule() and
2111-
a.getATarget().(Name).getId() = "__metaclass__"
2111+
a.getATarget().(Name).getId() = "__metaclass__" and
2112+
a.getValue() = API::builtin("type").getAValueReachableFromSource().asExpr()
21122113
)
21132114
)
21142115
}

0 commit comments

Comments
 (0)