Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-39573: Update clinic to use Py_IS_TYPE macro #18507

Merged
merged 2 commits into from
Feb 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update clinic tool to use :c:func:`Py_IS_TYPE`. Patch by Dong-hee Na.
4 changes: 2 additions & 2 deletions Modules/_io/clinic/bufferedio.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -672,4 +672,4 @@ _io_BufferedRandom___init__(PyObject *self, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
/*[clinic end generated code: output=7246104f6c7d3167 input=a9049054013a1b77]*/
/*[clinic end generated code: output=7d9ad40c95bdd808 input=a9049054013a1b77]*/
8 changes: 4 additions & 4 deletions Modules/clinic/_bz2module.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Objects/clinic/listobject.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 6 additions & 9 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3585,17 +3585,14 @@ def set_template_dict(self, template_dict):
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)

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)
type_check = 'Py_IS_TYPE({}, {})'.format(self.name, type_object)

line = '{} &&\n '.format(type_check)
template_dict['self_type_check'] = line



Expand Down