If an error in your #Python program seems impossible, double-check that you haven't edited the source after starting the program. Tracebacks re-read the source files to show the lines of code, so they can show you edited lines that aren't what you are running.
@nedbat holy shit I never knew this! I've probably been there several times without realizing.
Related, there have definitely been some times I've done a voodoo clearing of .pyc files because I swore it was not running the most recent code