Skip to content

Commit 1ce77ff

Browse files
authored
Merge pull request #2507 from tausbn/python-fix-infinite-tuple-tostring
Python: Fix divergence in tuple `toString`.
2 parents 8a6de11 + 3cebffe commit 1ce77ff

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,13 @@ abstract class TupleObjectInternal extends SequenceObjectInternal {
5353
}
5454

5555
private string item(int n) {
56-
result = this.getItem(n).toString()
56+
exists(ObjectInternal item | item = this.getItem(n) |
57+
// To avoid infinite recursion, nested tuples are replaced with the string "...".
58+
if item instanceof TupleObjectInternal then
59+
result = "(...)"
60+
else
61+
result = item.toString()
62+
)
5763
or
5864
n in [0..this.length()-1] and
5965
not exists(this.getItem(n)) and result = "?"

0 commit comments

Comments
 (0)