bpo-39573: Use Py_IS_TYPE for type checking by petdance · Pull Request #18789 · python/cpython

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?