From 60202609a2c2d0971aadfa4729ba30b50e89c6ea Mon Sep 17 00:00:00 2001 From: Lysandros Nikolaou Date: Wed, 30 Apr 2025 11:46:41 +0200 Subject: gh-132661: Implement PEP 750 (#132662) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Lysandros Nikolaou Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Co-authored-by: Wingy Co-authored-by: Koudai Aono Co-authored-by: Dave Peck Co-authored-by: Terry Jan Reedy Co-authored-by: Paul Everitt Co-authored-by: sobolevn --- Objects/unicodeobject.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'Objects/unicodeobject.c') diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index b3287546dd9..462323a828e 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -56,6 +56,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "pycore_pyhash.h" // _Py_HashSecret_t #include "pycore_pylifecycle.h" // _Py_SetFileSystemEncoding() #include "pycore_pystate.h" // _PyInterpreterState_GET() +#include "pycore_template.h" // _PyTemplate_Concat() #include "pycore_tuple.h" // _PyTuple_FromArray() #include "pycore_ucnhash.h" // _PyUnicode_Name_CAPI #include "pycore_unicodeobject.h" // struct _Py_unicode_state @@ -11628,10 +11629,16 @@ PyUnicode_Concat(PyObject *left, PyObject *right) return NULL; if (!PyUnicode_Check(right)) { - PyErr_Format(PyExc_TypeError, - "can only concatenate str (not \"%.200s\") to str", - Py_TYPE(right)->tp_name); - return NULL; + if (_PyTemplate_CheckExact(right)) { + // str + tstring is implemented in the tstring type + return _PyTemplate_Concat(left, right); + } + else { + PyErr_Format(PyExc_TypeError, + "can only concatenate str (not \"%.200s\") to str", + Py_TYPE(right)->tp_name); + return NULL; + } } /* Shortcuts */ -- cgit v1.2.3