From 9aeb0ef9309384099e2f23bcee2240fbc096568e Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Fri, 14 Feb 2020 16:50:19 +0900 Subject: [PATCH] bpo-39573: Update clinic to use Py_IS_TYPE() function (GH-18507) --- .../2020-02-14-10-08-53.bpo-39573.BIIX2M.rst | 1 + Modules/_io/clinic/bufferedio.c.h | 4 ++-- Modules/clinic/_bz2module.c.h | 8 ++++---- Objects/clinic/listobject.c.h | 4 ++-- Tools/clinic/clinic.py | 13 +++++-------- 5 files changed, 14 insertions(+), 16 deletions(-) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2020-02-14-10-08-53.bpo-39573.BIIX2M.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-02-14-10-08-53.bpo-39573.BIIX2M.rst b/Misc/NEWS.d/next/Core and Builtins/2020-02-14-10-08-53.bpo-39573.BIIX2M.rst new file mode 100644 index 00000000000..23396d3bd2b --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-02-14-10-08-53.bpo-39573.BIIX2M.rst @@ -0,0 +1 @@ +Update clinic tool to use :c:func:`Py_IS_TYPE`. Patch by Dong-hee Na. diff --git a/Modules/_io/clinic/bufferedio.c.h b/Modules/_io/clinic/bufferedio.c.h index 72841fcb677..56d6332a250 100644 --- a/Modules/_io/clinic/bufferedio.c.h +++ b/Modules/_io/clinic/bufferedio.c.h @@ -578,7 +578,7 @@ _io_BufferedRWPair___init__(PyObject *self, PyObject *args, PyObject *kwargs) PyObject *writer; Py_ssize_t buffer_size = DEFAULT_BUFFER_SIZE; - if ((Py_TYPE(self) == &PyBufferedRWPair_Type) && + if (Py_IS_TYPE(self, &PyBufferedRWPair_Type) && !_PyArg_NoKeywords("BufferedRWPair", kwargs)) { goto exit; } @@ -672,4 +672,4 @@ skip_optional_pos: exit: return return_value; } -/*[clinic end generated code: output=7246104f6c7d3167 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=7d9ad40c95bdd808 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_bz2module.c.h b/Modules/clinic/_bz2module.c.h index ac826bd9b59..0eb6280d6e0 100644 --- a/Modules/clinic/_bz2module.c.h +++ b/Modules/clinic/_bz2module.c.h @@ -85,7 +85,7 @@ _bz2_BZ2Compressor___init__(PyObject *self, PyObject *args, PyObject *kwargs) int return_value = -1; int compresslevel = 9; - if ((Py_TYPE(self) == &BZ2Compressor_Type) && + if (Py_IS_TYPE(self, &BZ2Compressor_Type) && !_PyArg_NoKeywords("BZ2Compressor", kwargs)) { goto exit; } @@ -207,11 +207,11 @@ _bz2_BZ2Decompressor___init__(PyObject *self, PyObject *args, PyObject *kwargs) { int return_value = -1; - if ((Py_TYPE(self) == &BZ2Decompressor_Type) && + if (Py_IS_TYPE(self, &BZ2Decompressor_Type) && !_PyArg_NoPositional("BZ2Decompressor", args)) { goto exit; } - if ((Py_TYPE(self) == &BZ2Decompressor_Type) && + if (Py_IS_TYPE(self, &BZ2Decompressor_Type) && !_PyArg_NoKeywords("BZ2Decompressor", kwargs)) { goto exit; } @@ -220,4 +220,4 @@ _bz2_BZ2Decompressor___init__(PyObject *self, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=ec3d1b3652c98823 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=3f3f1e788fe28ee1 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/listobject.c.h b/Objects/clinic/listobject.c.h index 57f0a48eb08..ed137c95a8e 100644 --- a/Objects/clinic/listobject.c.h +++ b/Objects/clinic/listobject.c.h @@ -314,7 +314,7 @@ list___init__(PyObject *self, PyObject *args, PyObject *kwargs) int return_value = -1; PyObject *iterable = NULL; - if ((Py_TYPE(self) == &PyList_Type) && + if (Py_IS_TYPE(self, &PyList_Type) && !_PyArg_NoKeywords("list", kwargs)) { goto exit; } @@ -367,4 +367,4 @@ list___reversed__(PyListObject *self, PyObject *Py_UNUSED(ignored)) { return list___reversed___impl(self); } -/*[clinic end generated code: output=73718c0c33798c62 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=1ff61490c091d165 input=a9049054013a1b77]*/ diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index b503932e262..382e29a28ab 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -3585,17 +3585,14 @@ class self_converter(CConverter): cls = self.function.cls if ((kind in (METHOD_NEW, METHOD_INIT)) and cls and cls.typedef): + type_object = self.function.cls.type_object if kind == METHOD_NEW: - passed_in_type = self.name + type_check = '({} == {})'.format(self.name, type_object) else: - passed_in_type = 'Py_TYPE({})'.format(self.name) + type_check = 'Py_IS_TYPE({}, {})'.format(self.name, type_object) - line = '({passed_in_type} == {type_object}) &&\n ' - d = { - 'type_object': self.function.cls.type_object, - 'passed_in_type': passed_in_type - } - template_dict['self_type_check'] = line.format_map(d) + line = '{} &&\n '.format(type_check) + template_dict['self_type_check'] = line