Skip to content

Commit c871984

Browse files
committed
Python: Extend DuckTyping module
Adds `overridesMethod` and `isPropertyAccessor`.
1 parent bf3e152 commit c871984

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,4 +2061,21 @@ module DuckTyping {
20612061
* resolved according to the MRO.
20622062
*/
20632063
Function getInit(Class cls) { result = invokedFunctionFromClassConstruction(cls, "__init__") }
2064+
2065+
/**
2066+
* Holds if `f` overrides a method in a superclass with the same name.
2067+
*/
2068+
predicate overridesMethod(Function f) {
2069+
exists(Class cls | f.getScope() = cls | hasMethod(getADirectSuperclass(cls), f.getName()))
2070+
}
2071+
2072+
/**
2073+
* Holds if `f` is a property accessor (decorated with `@property`, `@name.setter`,
2074+
* or `@name.deleter`).
2075+
*/
2076+
predicate isPropertyAccessor(Function f) {
2077+
exists(Attribute a | a = f.getADecorator() | a.getName() = "setter" or a.getName() = "deleter")
2078+
or
2079+
f.getADecorator().(Name).getId() = "property"
2080+
}
20642081
}

0 commit comments

Comments
 (0)