Skip to content

Commit 25dc827

Browse files
committed
bpo-39573: Update clinic to use Py_IS_TYPE macro
1 parent f632736 commit 25dc827

File tree

5 files changed

+15
-17
lines changed

5 files changed

+15
-17
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update clinic tool to use :c:func:`Py_IS_TYPE`. Patch by Dong-hee Na.

Modules/_io/clinic/bufferedio.c.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ _io_BufferedRWPair___init__(PyObject *self, PyObject *args, PyObject *kwargs)
578578
PyObject *writer;
579579
Py_ssize_t buffer_size = DEFAULT_BUFFER_SIZE;
580580

581-
if ((Py_TYPE(self) == &PyBufferedRWPair_Type) &&
581+
if (Py_IS_TYPE(self, &PyBufferedRWPair_Type) &&
582582
!_PyArg_NoKeywords("BufferedRWPair", kwargs)) {
583583
goto exit;
584584
}
@@ -672,4 +672,4 @@ _io_BufferedRandom___init__(PyObject *self, PyObject *args, PyObject *kwargs)
672672
exit:
673673
return return_value;
674674
}
675-
/*[clinic end generated code: output=7246104f6c7d3167 input=a9049054013a1b77]*/
675+
/*[clinic end generated code: output=7d9ad40c95bdd808 input=a9049054013a1b77]*/

Modules/clinic/_bz2module.c.h

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Objects/clinic/listobject.c.h

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tools/clinic/clinic.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -3585,17 +3585,14 @@ def set_template_dict(self, template_dict):
35853585
cls = self.function.cls
35863586

35873587
if ((kind in (METHOD_NEW, METHOD_INIT)) and cls and cls.typedef):
3588+
type_object = self.function.cls.type_object
35883589
if kind == METHOD_NEW:
3589-
passed_in_type = self.name
3590+
type_check = '({} == {})'.format(self.name, type_object)
35903591
else:
3591-
passed_in_type = 'Py_TYPE({})'.format(self.name)
3592-
3593-
line = '({passed_in_type} == {type_object}) &&\n '
3594-
d = {
3595-
'type_object': self.function.cls.type_object,
3596-
'passed_in_type': passed_in_type
3597-
}
3598-
template_dict['self_type_check'] = line.format_map(d)
3592+
type_check = 'Py_IS_TYPE({}, {})'.format(self.name, type_object)
3593+
3594+
line = '{} &&\n '.format(type_check)
3595+
template_dict['self_type_check'] = line
35993596

36003597

36013598

0 commit comments

Comments
 (0)