Conversation with @KeyboardInterrupt has made it clear that this is originally a py2 codebase from 2016. It needs type hinting as the start of cleanup, as well as replacing some of the int parsing with use of the struct module.