This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author yselivanov
Recipients alex.gronholm, asvetlov, eric.snow, yselivanov
Date 2018-08-09.14:55:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1533826528.24.0.56676864532.issue34270@psf.upfronthosting.co.za>
In-reply-to
Content
> 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.
History
Date User Action Args
2018-08-09 14:55:28yselivanovsetrecipients: + yselivanov, asvetlov, alex.gronholm, eric.snow
2018-08-09 14:55:28yselivanovsetmessageid: <1533826528.24.0.56676864532.issue34270@psf.upfronthosting.co.za>
2018-08-09 14:55:28yselivanovlinkissue34270 messages
2018-08-09 14:55:28yselivanovcreate