Serhiy Storchaka <storchaka+cpyt...@gmail.com> added the comment:

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].

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue44194>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to