You write your code as if you where using QString objects. With either PySide2 or PyQt5 you'll have Python str objects. You need to translate these bits.
I'm still kind of new to writing Qt in Python...
changing my code to using pin[:-1] works as expected! Thanks!