8000 [mypyc] Fix bytes join on Python 3.13 · python/mypy@023861e · GitHub
[go: up one dir, main page]

Skip to content

Commit 023861e

Browse files
committed
[mypyc] Fix bytes join on Python 3.13
`_PyBytes_Join` is no longer available. Work on mypyc/mypyc#1056.
1 parent 6a0657e commit 023861e

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

mypyc/lib-rt/bytes_ops.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,26 @@ PyObject *CPyBytes_GetSlice(PyObject *obj, CPyTagged start, CPyTagged end) {
9595
return CPyObject_GetSlice(obj, start, end);
9696
}
9797

98-
// Like _PyBytes_Join but fallback to dynamic call if 'sep' is not bytes
99-
// (mostly commonly, for bytearrays)
10098
PyObject *CPyBytes_Join(PyObject *sep, PyObject *iter) {
99+
#if CPY_3_13_FEATURES
100+
PyObject *args[2] = {sep, iter};
101+
_Py_IDENTIFIER(join);
102+
PyObject *method = _PyUnicode_FromId(&PyId_join); /* borrowed */
103+
if (method == NULL) {
104+
return NULL;
105+
}
106+
PyObject *res = PyObject_VectorcallMethod(
107+
method, args, 2 | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL);
108+
return res;
109+
#else
110+
// Fallback to dynamic call if 'sep' is not bytes (most commonly, for bytearrays)
101111
if (PyBytes_CheckExact(sep)) {
102112
return _PyBytes_Join(sep, iter);
103113
} else {
104114
_Py_IDENTIFIER(join);
105115
return _PyObject_CallMethodIdOneArg(sep, &PyId_join, iter);
106116
}
117+
#endif
107118
}
108119

109120
PyObject *CPyBytes_Build(Py_ssize_t len, ...) {

0 commit comments

Comments
 (0)
0