python - When is a str not a str? -
i have issue in python3 str not str. i'm working through 2to3 project, , i'm getting failure due type check in third party class. it's worth didn't happen under python 2. following example not error similar issue:
class theirclass(): # don't love they're using `id` here, def __init__(self, name, id=none): if isinstance(name, str): self.name = name else: raise typeerror('name not str') my_object = theirclass('a name') print('yep worked') i haven't yet been able reduce mcve, know following things:
- i passing
strconstructortheirclass.name - outside
theirclass.__init__isinstance(name, str) == true - inside
theirclass.__init__isinstance(name, str) == false - inside
theirclass.__init__type(name)returns<class str> - inside
theirclass.__init__dir(name) == dir(str) inspect.getmroreports pseudo-str doesn't have__mro__- after renaming
idin code able seeid(str) != id(type(name)) - the
idofnameobject not change between 2 method calls
as far can tell nobody redefining isinstance or str. id of str does change outside constructor of theirclass inside of it.
the final clue id of str changed. while there no assignment of str or def str there import. specifically:
from past.builtins import str
Comments
Post a Comment