This is the kind of wisdom that comes after hours of debugging and discovering the bug was your own variable reuse.
Wouldn't this be an easy task for SCA tool e.g. Pylint? It has atleast warning against variable redefinition: https://pylint.pycqa.org/en/latest/user_guide/messages/refac...
replies(1):