mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +01:00
Python: Fix scope of type parameters
This takes care of scoping for type parameters on functions, but not type aliases or classes. For classes, the _type parameters_ now have the correct `Class` as scope, but all their child nodes do not (e.g. the `Name` inside a `TypeParameter`). This has to do with how the `py_scopes` relation is emitted by the extractor, since `Name`s are expressions.
This commit is contained in:
@@ -229,9 +229,12 @@ class TypeParameter extends TypeParameter_, AstNode {
|
|||||||
override AstNode getAChildNode() { none() }
|
override AstNode getAChildNode() { none() }
|
||||||
|
|
||||||
override Scope getScope() {
|
override Scope getScope() {
|
||||||
// `TypeParameter`s are children of `TypeParameterList`s which are children of `Function`s, `ClassExpr`s, and `TypeAlias`es.
|
exists(Function f | this = f.getATypeParameter() and result = f)
|
||||||
|
or
|
||||||
|
exists(ClassExpr c | this = c.getATypeParameter() and result = c.getInnerScope())
|
||||||
|
or
|
||||||
// For `TypeAlias`, this is not quite right. Instead, `TypeAlias`es should define their own scopes, cf. https://docs.python.org/3.12/reference/executionmodel.html#annotation-scopes
|
// For `TypeAlias`, this is not quite right. Instead, `TypeAlias`es should define their own scopes, cf. https://docs.python.org/3.12/reference/executionmodel.html#annotation-scopes
|
||||||
result = this.getParent().getParent().(AstNode).getScope()
|
exists(TypeAlias t | this = t.getATypeParameter() and result = t.getScope())
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Gets the location of this element */
|
/** Gets the location of this element */
|
||||||
|
|||||||
Reference in New Issue
Block a user