Skip to content

bpo-39573: Use Py_IS_TYPE for type checking - #18789

Closed
petdance wants to merge 2 commits into
python:masterfrom
petdance:bpo-39573-B
Closed

bpo-39573: Use Py_IS_TYPE for type checking#18789
petdance wants to merge 2 commits into
python:masterfrom
petdance:bpo-39573-B

Conversation

@petdance

@petdancepetdance commented Mar 5, 2020

Copy link
Copy Markdown
Contributor

This finishes up the conversions to using Py_IS_TYPE for checking object types.

It also updates Py_IS_TYPE(ob, type) to be able to take a const objects and a const type.

https://bugs.python.org/issue39573

Comment threadInclude/object.h
static inline int _Py_IS_TYPE(const PyObject *ob, const PyTypeObject *type) {
return ob->ob_type == type;
}
#define Py_IS_TYPE(ob, type) _Py_IS_TYPE(_PyObject_CAST(ob), type)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would prefer to have a new private _PyObject_CAST_CONST() macro rather than casting directly.

I prefer macros because maybe tomorrow we might be able to check if the pointer is valid PyObject in debug mode. Maybe using _PyObject_CheckConsistency().

Would you mind to move these changes (add the macro and modify Py_IS_TYPE to use const) into a separated PR?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Sure, I'll make two separate PRs.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

They are now in #18798 and #18799

@vstinner

Copy link
Copy Markdown
Member

I merged PR #18809.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@petdance@vstinner@the-knights-who-say-ni@bedevere-bot