Python NameError hid for months by lazy evaluation, caught only by AST static analysis
A browser automation tool began throwing a Python NameError after a code refactor in version 1.6.1 moved a local variable into a new function, while a residual check in the original function continued referencing the now-out-of-scope name. Because Python resolves variable names only at runtime rather than at import time, the bug remained invisible during normal startup and SSH-based update paths. The error only surfaced when the specific browser-automation code path executed, meaning it went undetected for multiple release cycles. The fix promoted the variable to a module-level constant accessible by both functions. To prevent similar issues, the team added an AST-based static analysis test to automatically detect dangling variable references across function boundaries.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in