Why this matters
Using undefined variables, functions, or classes leads to NameError and prevents code from running.
Check for variables, functions, or classes that are used but not defined. This results in NameError and should be fixed by ensuring all symbols are properly declared.
Using undefined variables, functions, or classes leads to NameError and prevents code from running.
Side-by-side examples engineers can pattern-match during review.
my_var # Noncompliant (variable is never defined)
def noncompliant():
foo() # Noncompliant
MyClass() # Noncompliantfrom mod import my_var
my_var
def compliant():
foo = sum
foo()
class MyClass:
pass
MyClass()From the same buckets as this rule.
Check if loops use equality operators (== or !=) in termination conditions. These can lead to infinite loops if the condition is never met exactly. Instead, use relational operators like < or > for safer loop termination.