Yury Selivanov <[email protected]> added the comment:
> I also couldn't figure out yet why PyUnicode_Check() was necessary in the
> first place. Doesn't PyObject_Str() just increment the refcount if the
> argument is already a string?
`str()` returns its argument if it's exactly a `builtins.str` instance. If
it's a subclass of str, it will construct a `builtins.str` out of it.
>>> class mystr(str):
... pass
>>> a = mystr('aaa')
>>> str(a) is a
False
So Eric is right, there's a small discrepancy between Python and C version.
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue34270>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com