I understand that the following behavior is not guaranteed:
>>> x = "Hello, world!"
>>> y = "Hello, world!"
>>> assert x is y
But, is this behavior guaranteed:
>>> x = "Hello, world!"
>>> y = str(x)
>>> assert x is y
If so, what is the correct way to implement this behavior in my own (immutable) classes?
EDIT: By "this behavior" I mean "a constructor for a class that should reuse an existing instance":
>>> x = MyClass("abc", 123)
>>> y = MyClass(x)
>>> assert x is y