Movatterモバイル変換


[0]ホーム

URL:


CodeQL documentation
CodeQL resources

Non-iterable used in for loop

ID: py/non-iterable-in-for-loopKind: problemSecurity severity: Severity: errorPrecision: highTags:   - quality   - reliability   - correctnessQuery suites:   - python-security-and-quality.qls

Click to see the query in the CodeQL repository

Thefor statement is designed to allow you to iterate over the elements of a sequence or other iterable object. If a non-iterable object is used in afor statement (forvarinobject:) then a TypeError will be raised.

Recommendation

Since this defect usually indicates a logical error, it is not possible to give a general method for addressing the defect.

Example

In this example, the loop may attempt to iterate overNone, which is not an iterable. It is likely that the programmer forgot to test forNone before the loop.

defillegal_for_loop(seq=None):forxinseq:print(x)

References


[8]ページ先頭

©2009-2025 Movatter.jp