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 str constructor theirclass.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.getmro reports pseudo-str doesn't have __mro__
  • after renaming id in code able see id(str) != id(type(name))
  • the id of name object 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

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -