mirror of
https://github.com/github/codeql.git
synced 2026-03-31 12:48:17 +02:00
Python: Extend DuckTyping module
Adds `overridesMethod` and `isPropertyAccessor`.
This commit is contained in:
@@ -2111,4 +2111,27 @@ module DuckTyping {
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the `__init__` function that will be invoked when `cls` is constructed,
|
||||
* resolved according to the MRO.
|
||||
*/
|
||||
Function getInit(Class cls) { result = invokedFunctionFromClassConstruction(cls, "__init__") }
|
||||
|
||||
/**
|
||||
* Holds if `f` overrides a method in a superclass with the same name.
|
||||
*/
|
||||
predicate overridesMethod(Function f) {
|
||||
exists(Class cls | f.getScope() = cls | hasMethod(getADirectSuperclass(cls), f.getName()))
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if `f` is a property accessor (decorated with `@property`, `@name.setter`,
|
||||
* or `@name.deleter`).
|
||||
*/
|
||||
predicate isPropertyAccessor(Function f) {
|
||||
exists(Attribute a | a = f.getADecorator() | a.getName() = "setter" or a.getName() = "deleter")
|
||||
or
|
||||
f.getADecorator().(Name).getId() = "property"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user