Skip to content

Files

Latest commit

 

History

History
26 lines (19 loc) · 531 Bytes

possibly-used-before-assignment.md

File metadata and controls

26 lines (19 loc) · 531 Bytes

Pattern: Possibly using variable before assignment

Issue: -

Description

Emitted when a local variable is accessed before its assignment took place in both branches of an if/else switch.

Example of incorrect code:

def check_lunchbox(items: list[str]):
    if not items:
        empty = True
    print(empty)  # [possibly-used-before-assignment]

Example of correct code:

def check_lunchbox(items: list[str]):
    empty = False
    if not items:
        empty = True
    print(empty)