Skip to content

Commit 9581b8f

Browse files
committed
Python: Extend DuckTyping module
Adds `overridesMethod` and `isPropertyAccessor`.
1 parent 8e3ce92 commit 9581b8f

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
@@ -2096,4 +2096,21 @@ module DuckTyping {
20962096
* resolved according to the MRO.
20972097
*/
20982098
Function getInit(Class cls) { result = invokedFunctionFromClassConstruction(cls, "__init__") }
2099+
2100+
/**
2101+
* Holds if `f` overrides a method in a superclass with the same name.
2102+
*/
2103+
predicate overridesMethod(Function f) {
2104+
exists(Class cls | f.getScope() = cls | hasMethod(getADirectSuperclass(cls), f.getName()))
2105+
}
2106+
2107+
/**
2108+
* Holds if `f` is a property accessor (decorated with `@property`, `@name.setter`,
2109+
* or `@name.deleter`).
2110+
*/
2111+
predicate isPropertyAccessor(Function f) {
2112+
exists(Attribute a | a = f.getADecorator() | a.getName() = "setter" or a.getName() = "deleter")
2113+
or
2114+
f.getADecorator().(Name).getId() = "property"
2115+
}
20992116
}

0 commit comments

Comments
 (0)