Skip to content

Commit 712fb8b

Browse files
committed
Python: ObjectAPI to ValueAPI: IterReturnsNonSelf: Autoformats
1 parent cdda806 commit 712fb8b

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

python/ql/src/Functions/IterReturnsNonSelf.ql

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212

1313
import python
1414

15-
Function iter_method(ClassValue t) {
16-
result = ((FunctionValue)t.lookup("__iter__")).getScope()
17-
}
15+
Function iter_method(ClassValue t) { result = t.lookup("__iter__").(FunctionValue).getScope() }
1816

1917
predicate is_self(Name value, Function f) { value.getVariable() = f.getArg(0).(Name).getVariable() }
2018

python/ql/src/semmle/python/objects/ObjectAPI.qll

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -432,24 +432,27 @@ class ClassValue extends Value {
432432

433433
/** Holds if this class is an iterator. */
434434
predicate isIterator() {
435-
this.hasAttribute("__iter__") and
436-
(major_version() = 3 and this.hasAttribute("__next__")
437-
or
438-
/* Because 'next' is a common method name we need to check that an __iter__
439-
* method actually returns this class. This is not needed for Py3 as the
440-
* '__next__' method exists to define a class as an iterator.
441-
*/
442-
major_version() = 2 and this.hasAttribute("next") and
443-
exists(ClassValue other, FunctionValue iter |
444-
other.declaredAttribute("__iter__") = iter |
445-
iter.getAnInferredReturnType() = this
446-
)
435+
this.hasAttribute("__iter__") and
436+
(
437+
major_version() = 3 and this.hasAttribute("__next__")
438+
or
439+
/*
440+
* Because 'next' is a common method name we need to check that an __iter__
441+
* method actually returns this class. This is not needed for Py3 as the
442+
* '__next__' method exists to define a class as an iterator.
443+
*/
444+
445+
major_version() = 2 and
446+
this.hasAttribute("next") and
447+
exists(ClassValue other, FunctionValue iter | other.declaredAttribute("__iter__") = iter |
448+
iter.getAnInferredReturnType() = this
449+
)
447450
)
448451
or
449452
/* This will be redundant when we have C class information */
450453
this = ClassValue::generator()
451454
}
452-
455+
453456
/** Holds if this class is a container(). That is, does it have a __getitem__ method. */
454457
predicate isContainer() { exists(this.lookup("__getitem__")) }
455458

0 commit comments

Comments
 (0)