Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f19b672

Browse files
committed
Python: Also capture alias with new name
1 parent e7d5573 commit f19b672

3 files changed

Lines changed: 8 additions & 3 deletions

File tree

python/ql/lib/semmle/python/frameworks/internal/SubclassFinder.qll

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,12 @@ module NotExposed {
190190
string relevantName, Location loc
191191
) {
192192
loc = mod.getLocation() and
193-
exists(API::Node relevantClass, ClassExpr classExpr |
193+
exists(API::Node relevantClass, Expr value |
194194
relevantClass = newOrExistingModeling(spec).getASubclass*() and
195195
ImportResolution::module_export(mod, relevantName, def) and
196-
classExpr = relevantClass.asSource().asExpr() and
197-
classExpr = def.asVar().getDefinition().(AssignmentDefinition).getValue().getNode()
196+
value = relevantClass.getAValueReachableFromSource().asExpr() and
197+
value = def.asVar().getDefinition().(AssignmentDefinition).getValue().getNode()
198+
// value could be a ClassExpr if a new class is defined, or a Name if defining an alias
198199
) and
199200
(
200201
mod.isPackageInit() and
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
| flask.View~Subclass | find_subclass_test | Member[A] |
22
| flask.View~Subclass | find_subclass_test | Member[B] |
3+
| flask.View~Subclass | find_subclass_test | Member[ViewAlias] |
34
| flask.View~Subclass | find_subclass_test | Member[View] |

python/ql/test/experimental/library-tests/FindSubclass/find_subclass_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ class A(View):
55

66
class B(A):
77
pass
8+
9+
10+
ViewAlias = View

0 commit comments

Comments
 (0)