bpo-39573: Update clinic to use Py_IS_TYPE() function (GH-18507)

This commit is contained in:
Dong-hee Na 2020-02-14 16:50:19 +09:00 committed by GitHub
parent d212c3c55d
commit 9aeb0ef930
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 16 deletions

View File

@ -0,0 +1 @@
Update clinic tool to use :c:func:`Py_IS_TYPE`. Patch by Dong-hee Na.

View File

@ -578,7 +578,7 @@ _io_BufferedRWPair___init__(PyObject *self, PyObject *args, PyObject *kwargs)
PyObject *writer; PyObject *writer;
Py_ssize_t buffer_size = DEFAULT_BUFFER_SIZE; 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)) { !_PyArg_NoKeywords("BufferedRWPair", kwargs)) {
goto exit; goto exit;
} }
@ -672,4 +672,4 @@ skip_optional_pos:
exit: exit:
return return_value; return return_value;
} }
/*[clinic end generated code: output=7246104f6c7d3167 input=a9049054013a1b77]*/ /*[clinic end generated code: output=7d9ad40c95bdd808 input=a9049054013a1b77]*/

View File

@ -85,7 +85,7 @@ _bz2_BZ2Compressor___init__(PyObject *self, PyObject *args, PyObject *kwargs)
int return_value = -1; int return_value = -1;
int compresslevel = 9; int compresslevel = 9;
if ((Py_TYPE(self) == &BZ2Compressor_Type) && if (Py_IS_TYPE(self, &BZ2Compressor_Type) &&
!_PyArg_NoKeywords("BZ2Compressor", kwargs)) { !_PyArg_NoKeywords("BZ2Compressor", kwargs)) {
goto exit; goto exit;
} }
@ -207,11 +207,11 @@ _bz2_BZ2Decompressor___init__(PyObject *self, PyObject *args, PyObject *kwargs)
{ {
int return_value = -1; int return_value = -1;
if ((Py_TYPE(self) == &BZ2Decompressor_Type) && if (Py_IS_TYPE(self, &BZ2Decompressor_Type) &&
!_PyArg_NoPositional("BZ2Decompressor", args)) { !_PyArg_NoPositional("BZ2Decompressor", args)) {
goto exit; goto exit;
} }
if ((Py_TYPE(self) == &BZ2Decompressor_Type) && if (Py_IS_TYPE(self, &BZ2Decompressor_Type) &&
!_PyArg_NoKeywords("BZ2Decompressor", kwargs)) { !_PyArg_NoKeywords("BZ2Decompressor", kwargs)) {
goto exit; goto exit;
} }
@ -220,4 +220,4 @@ _bz2_BZ2Decompressor___init__(PyObject *self, PyObject *args, PyObject *kwargs)
exit: exit:
return return_value; return return_value;
} }
/*[clinic end generated code: output=ec3d1b3652c98823 input=a9049054013a1b77]*/ /*[clinic end generated code: output=3f3f1e788fe28ee1 input=a9049054013a1b77]*/

View File

@ -314,7 +314,7 @@ list___init__(PyObject *self, PyObject *args, PyObject *kwargs)
int return_value = -1; int return_value = -1;
PyObject *iterable = NULL; PyObject *iterable = NULL;
if ((Py_TYPE(self) == &PyList_Type) && if (Py_IS_TYPE(self, &PyList_Type) &&
!_PyArg_NoKeywords("list", kwargs)) { !_PyArg_NoKeywords("list", kwargs)) {
goto exit; goto exit;
} }
@ -367,4 +367,4 @@ list___reversed__(PyListObject *self, PyObject *Py_UNUSED(ignored))
{ {
return list___reversed___impl(self); return list___reversed___impl(self);
} }
/*[clinic end generated code: output=73718c0c33798c62 input=a9049054013a1b77]*/ /*[clinic end generated code: output=1ff61490c091d165 input=a9049054013a1b77]*/

View File

@ -3585,17 +3585,14 @@ class self_converter(CConverter):
cls = self.function.cls cls = self.function.cls
if ((kind in (METHOD_NEW, METHOD_INIT)) and cls and cls.typedef): if ((kind in (METHOD_NEW, METHOD_INIT)) and cls and cls.typedef):
type_object = self.function.cls.type_object
if kind == METHOD_NEW: if kind == METHOD_NEW:
passed_in_type = self.name type_check = '({} == {})'.format(self.name, type_object)
else: 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 ' line = '{} &&\n '.format(type_check)
d = { template_dict['self_type_check'] = line
'type_object': self.function.cls.type_object,
'passed_in_type': passed_in_type
}
template_dict['self_type_check'] = line.format_map(d)