Skip to content

Convert PyBool_Check, PyBytes_Check & PyBytes_CheckExact macro to a function - #149558

Draft
bschoenmaeckers wants to merge 7 commits into
python:mainfrom
bschoenmaeckers:bool_check_static_function
Draft

Convert PyBool_Check, PyBytes_Check & PyBytes_CheckExact macro to a function#149558
bschoenmaeckers wants to merge 7 commits into
python:mainfrom
bschoenmaeckers:bool_check_static_function

Conversation

@bschoenmaeckers

Copy link
Copy Markdown

As discussed at https://discuss.python.org/t/c-api-add-py-getbuildintype-and-py-getbuildintypeborrowed/107010/12.

This converts the first type check macro to a function export instead when compiling for the limited api.

@bedevere-app

bedevere-app Bot commented May 8, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@python-cla-bot

python-cla-bot Bot commented May 8, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@bschoenmaeckers
bschoenmaeckers force-pushed the bool_check_static_function branch from 112f4a9 to df45d6b Compare May 8, 2026 12:45
@read-the-docs-community

read-the-docs-community Bot commented May 8, 2026

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #32606787 | 📁 Comparing 63e3c03 against main (5784119)

  🔍 Preview build  

4 files changed
± c-api/bool.html
± c-api/stable.html
± whatsnew/3.16.html
± whatsnew/changelog.html

@bedevere-app

bedevere-app Bot commented May 8, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

Comment thread Lib/test/test_stable_abi_ctypes.py
Comment thread Include/boolobject.h Outdated
Comment thread Objects/boolobject.c Outdated
Comment on lines +26 to +33
#undef PyBool_Check

int
PyBool_Check(PyObject *x)
{
return Py_IS_TYPE(x, &PyBool_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.

These should be at the end of the file, so all the internal implementations see the macro version.


These will become repetitive enough that I'd prefer condensed formatting (per the first rule in PEP 7):

// Implementations for the Stable ABI

#undef PyBool_Check
int PyBool_Check(PyObject *x) { return Py_IS_TYPE(x, &PyBool_Type); }

But @vstinner might disagree with that :)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I've moved it to the end of the file and used the condensed formatting.

Comment thread Include/boolobject.h Outdated
Comment thread Lib/test/test_stable_abi_ctypes.py
Co-authored-by: Petr Viktorin <encukou@gmail.com>
@bedevere-app

bedevere-app Bot commented May 8, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

2 similar comments
@bedevere-app

bedevere-app Bot commented May 8, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@bedevere-app

bedevere-app Bot commented May 8, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

bschoenmaeckers and others added 2 commits May 8, 2026 18:28
Co-authored-by: Petr Viktorin <encukou@gmail.com>
@bschoenmaeckers
bschoenmaeckers force-pushed the bool_check_static_function branch from 63e3c03 to f2a576f Compare May 8, 2026 16:29
@bedevere-app

bedevere-app Bot commented May 8, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@encukou

encukou commented May 11, 2026

Copy link
Copy Markdown
Member

PyBool_Check looks good; the next step would be e.g. PyBytes_Check & PyBytes_CheckExact, to show how this will look with the subclassable types.

@bschoenmaeckers

Copy link
Copy Markdown
Author

PyBool_Check looks good; the next step would be e.g. PyBytes_Check & PyBytes_CheckExact, to show how this will look with the subclassable types.

Great! Do you want me to do it in this PR?

@bschoenmaeckers
bschoenmaeckers force-pushed the bool_check_static_function branch from e125de5 to f787075 Compare May 11, 2026 10:26
@encukou

encukou commented May 11, 2026

Copy link
Copy Markdown
Member

Yeah, it would fit the title ;)
Thanks!

@bschoenmaeckers bschoenmaeckers changed the title gh-000000: Convert PyBytes_Check macro to a function gh-000000: Convert PyBool_Check , PyBytes_Check & PyBytes_CheckExact macro to a function May 11, 2026
@bschoenmaeckers bschoenmaeckers changed the title gh-000000: Convert PyBool_Check , PyBytes_Check & PyBytes_CheckExact macro to a function gh-000000: Convert PyBool_Check, PyBytes_Check & PyBytes_CheckExact macro to a function May 11, 2026
@vstinner

Copy link
Copy Markdown
Member

I don't get the rationale for hiding the implementation details of these macros. I don't think that it's worth it.

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 90 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Aug 10, 2026
@vstinner vstinner changed the title gh-000000: Convert PyBool_Check, PyBytes_Check & PyBytes_CheckExact macro to a function Convert PyBool_Check, PyBytes_Check & PyBytes_CheckExact macro to a function Aug 10, 2026
@vstinner vstinner added the pending The issue will be closed if no feedback is provided label Aug 10, 2026
@vstinner

Copy link
Copy Markdown
Member

I don't get the rationale for hiding the implementation details of these macros. I don't think that it's worth it.

@bschoenmaeckers: Can you fix the issue in RustPython instead? See https://discuss.python.org/t/c-api-add-py-getbuildintype-and-py-getbuildintypeborrowed/107010/17.

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

Labels

pending The issue will be closed if no feedback is provided skip issue stale Stale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants