From d93b525e4986db12f703a75b1633813649cbae57 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Fri, 19 Jun 2020 09:02:54 +0200 Subject: [PATCH] Deprecate passing bytes to FT2Font.set_text. The bytes object was previously implicitly interpreted as a latin-1 str, but we're not on Py2 anymore :-) --- doc/api/api_changes_3.4/deprecations.rst | 4 ++++ src/ft2font_wrapper.cpp | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/doc/api/api_changes_3.4/deprecations.rst b/doc/api/api_changes_3.4/deprecations.rst index 097ecfda3a6e..ce239ee68771 100644 --- a/doc/api/api_changes_3.4/deprecations.rst +++ b/doc/api/api_changes_3.4/deprecations.rst @@ -1,2 +1,6 @@ Deprecations ------------ + +Passing `bytes` to ``FT2Font.set_text`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +... is deprecated, pass `str` instead. diff --git a/src/ft2font_wrapper.cpp b/src/ft2font_wrapper.cpp index 102cfbda3dac..e1e4df6c1458 100644 --- a/src/ft2font_wrapper.cpp +++ b/src/ft2font_wrapper.cpp @@ -642,6 +642,13 @@ static PyObject *PyFT2Font_set_text(PyFT2Font *self, PyObject *args, PyObject *k codepoints[i] = unistr[i]; } } else if (PyBytes_Check(textobj)) { + if (PyErr_WarnEx( + PyExc_FutureWarning, + "Passing bytes to FTFont.set_text is deprecated since Matplotlib " + "3.4 and support will be removed in Matplotlib 3.6; pass str instead", + 1)) { + return NULL; + } size = PyBytes_Size(textobj); codepoints.resize(size); char *bytestr = PyBytes_AsString(textobj);