Message394222
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]. |
|
Date |
User |
Action |
Args |
2021-05-23 20:02:09 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, rhettinger, eric.smith, pablogsal, BTaskaya |
2021-05-23 20:02:09 | serhiy.storchaka | set | messageid: <1621800129.56.0.796433367052.issue44194@roundup.psfhosted.org> |
2021-05-23 20:02:09 | serhiy.storchaka | link | issue44194 messages |
2021-05-23 20:02:09 | serhiy.storchaka | create | |
|