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 serhiy.storchaka
Recipients BTaskaya, eric.smith, pablogsal, rhettinger, serhiy.storchaka
Date 2021-05-23.20:02:09
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1621800129.56.0.796433367052.issue44194@roundup.psfhosted.org>
In-reply-to
Content
I only seen this idiom in the code of Argument Clinic (written by Larry). I am sure that it is used in third-party code, but I do not know how common is it.

As for the proposed code, checking that the value is a string is not enough.

1. It can be a str subclass with an overridden __format__. In this case the result will be different.
2. If it is a str subclass without an overridden __format__, the optimization adds an overhead for looking up and calling the __format__ method. It can reverse the benefit in this case.

To fix this you can skip formatting for this "converter". But there is a corner case for ''.join([value]). The result should always be a str. It may be complicated. You may need two new converter codes.

3. It is worth to merge consequent string constants and skip empty string constants. '/'.join([base, 'data', user_arg]) should produce [base, '/data/', user_arg] instead of [base, '/', 'data', '/', user_arg], and ''.join([base, 'data', user_arg]) should produce [base, 'data', user_arg] instead of [base, '', 'data', '', user_arg].
History
Date User Action Args
2021-05-23 20:02:09serhiy.storchakasetrecipients: + serhiy.storchaka, rhettinger, eric.smith, pablogsal, BTaskaya
2021-05-23 20:02:09serhiy.storchakasetmessageid: <1621800129.56.0.796433367052.issue44194@roundup.psfhosted.org>
2021-05-23 20:02:09serhiy.storchakalinkissue44194 messages
2021-05-23 20:02:09serhiy.storchakacreate