golang_str: Fix bstr/ustr %-formatting wrt tuple subclass
In 390fd810 (golang_str: bstr/ustr %-formatting) I've implemented percent formatting but missed to handle tuple-subclass argv correctly. For example the following works with std string: In [1]: import collections as cc In [5]: Point = cc.namedtuple('Point', ['x', 'y']) In [9]: 'α %s %s π' % Point('β','γ') Out[9]: '\xce\xb1 \xce\xb2 \xce\xb3 \xcf\x80' while it fails with ustr: In [8]: ustr('α %s %s π') % Point('β','γ') --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-8-4f1a97267f2a> in <module>() ----> 1 ustr('α %s %s π') % Point('β','γ') /home/kirr/src/tools/go/pygolang/golang/_golang_str.pyx in golang._golang._pyustr.__mod__() 850 # %-formatting 851 def __mod__(a, b): --> 852 return pyu(pyb(a).__mod__(b)) 853 def __rmod__(b, a): 854 # ("..." % x) calls "x.__rmod__()" for string subtypes /home/kirr/src/tools/go/pygolang/golang/_golang_str.pyx in golang._golang._pybstr.__mod__() 473 # %-formatting 474 def __mod__(a, b): --> 475 return _bprintf(a, b) 476 def __rmod__(b, a): 477 # ("..." % x) calls "x.__rmod__()" for string subtypes /home/kirr/src/tools/go/pygolang/golang/_golang_str.pyx in golang._golang._bprintf() 1648 1649 if isinstance(xarg, tuple): -> 1650 argv = xarg 1651 xarg = _missing 1652 TypeError: Expected tuple, got Point -> Fix that.
Showing
Please register or sign in to comment