Python: ObjectAPI to ValueAPI: IterReturnsNonSelf: Autoformats

This commit is contained in:
Rebecca Valentine
2020-04-02 09:19:41 -07:00
parent cdda80623d
commit 712fb8badc
2 changed files with 17 additions and 16 deletions

View File

@@ -12,9 +12,7 @@
import python
Function iter_method(ClassValue t) {
result = ((FunctionValue)t.lookup("__iter__")).getScope()
}
Function iter_method(ClassValue t) { result = t.lookup("__iter__").(FunctionValue).getScope() }
predicate is_self(Name value, Function f) { value.getVariable() = f.getArg(0).(Name).getVariable() }

View File

@@ -432,24 +432,27 @@ class ClassValue extends Value {
/** Holds if this class is an iterator. */
predicate isIterator() {
this.hasAttribute("__iter__") and
(major_version() = 3 and this.hasAttribute("__next__")
or
/* Because 'next' is a common method name we need to check that an __iter__
* method actually returns this class. This is not needed for Py3 as the
* '__next__' method exists to define a class as an iterator.
*/
major_version() = 2 and this.hasAttribute("next") and
exists(ClassValue other, FunctionValue iter |
other.declaredAttribute("__iter__") = iter |
iter.getAnInferredReturnType() = this
)
this.hasAttribute("__iter__") and
(
major_version() = 3 and this.hasAttribute("__next__")
or
/*
* Because 'next' is a common method name we need to check that an __iter__
* method actually returns this class. This is not needed for Py3 as the
* '__next__' method exists to define a class as an iterator.
*/
major_version() = 2 and
this.hasAttribute("next") and
exists(ClassValue other, FunctionValue iter | other.declaredAttribute("__iter__") = iter |
iter.getAnInferredReturnType() = this
)
)
or
/* This will be redundant when we have C class information */
this = ClassValue::generator()
}
/** Holds if this class is a container(). That is, does it have a __getitem__ method. */
predicate isContainer() { exists(this.lookup("__getitem__")) }