Skip to content

[mypyc] Use Py_TYPE and Py_IsNone #12233

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

Merged
merged 1 commit into from
Feb 22, 2022
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
4 changes: 2 additions & 2 deletions mypyc/lib-rt/dict_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ int CPyDict_UpdateInDisplay(PyObject *dict, PyObject *stuff) {
if (ret < 0) {
if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
PyErr_Format(PyExc_TypeError,
"'%.200s' object is not a mapping",
stuff->ob_type->tp_name);
"'%.200s' object is not a mapping",
Py_TYPE(stuff)->tp_name);
}
}
return ret;
Expand Down
2 changes: 1 addition & 1 deletion mypyc/lib-rt/exc_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ static PyObject *CPy_GetTypeName(PyObject *type) {
// Get the type of a value as a string, expanding tuples to include
// all the element types.
static PyObject *CPy_FormatTypeName(PyObject *value) {
if (value == Py_None) {
if (Py_IsNone(value)) {
return PyUnicode_FromString("None");
}

Expand Down
2 changes: 1 addition & 1 deletion mypyc/lib-rt/generic_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ PyObject *CPyObject_GetAttr3(PyObject *v, PyObject *name, PyObject *defl)

PyObject *CPyIter_Next(PyObject *iter)
{
return (*iter->ob_type->tp_iternext)(iter);
return (*Py_TYPE(iter)->tp_iternext)(iter);
}

PyObject *CPyNumber_Power(PyObject *base, PyObject *index)
Expand Down
7 changes: 3 additions & 4 deletions mypyc/lib-rt/misc_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
// These are registered in mypyc.primitives.misc_ops.

#include <Python.h>
#include "pythoncapi_compat.h"
#include "CPy.h"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant include.


PyObject *CPy_GetCoro(PyObject *obj)
{
// If the type has an __await__ method, call it,
// otherwise, fallback to calling __iter__.
PyAsyncMethods* async_struct = obj->ob_type->tp_as_async;
PyAsyncMethods* async_struct = Py_TYPE(obj)->tp_as_async;
if (async_struct != NULL && async_struct->am_await != NULL) {
return (async_struct->am_await)(obj);
} else {
Expand All @@ -25,7 +24,7 @@ PyObject *CPyIter_Send(PyObject *iter, PyObject *val)
// Do a send, or a next if second arg is None.
// (This behavior is to match the PEP 380 spec for yield from.)
_Py_IDENTIFIER(send);
if (val == Py_None) {
if (Py_IsNone(val)) {
return CPyIter_Next(iter);
} else {
return _PyObject_CallMethodIdOneArg(iter, &PyId_send, val);
Expand Down Expand Up @@ -640,7 +639,7 @@ CPy_Super(PyObject *builtins, PyObject *self) {
if (!super_type)
return NULL;
PyObject *result = PyObject_CallFunctionObjArgs(
super_type, (PyObject*)self->ob_type, self, NULL);
super_type, (PyObject*)Py_TYPE(self), self, NULL);
Py_DECREF(super_type);
return result;
}
Expand Down