Thanks to visit codestin.com
Credit goes to github.com

Skip to content

FIX: Inverted PyErr_Occurred check in enum type caster (_enums.h)#31556

Merged
ksunden merged 1 commit intomatplotlib:mainfrom
beelauuu:beelauuu/enums
Apr 23, 2026
Merged

FIX: Inverted PyErr_Occurred check in enum type caster (_enums.h)#31556
ksunden merged 1 commit intomatplotlib:mainfrom
beelauuu:beelauuu/enums

Conversation

@beelauuu
Copy link
Copy Markdown
Contributor

@beelauuu beelauuu commented Apr 23, 2026

PR summary

Fix an inverted error-check in the pybind11 enum type caster in src/_enums.h. PyLong_AsLong signals failure by returning -1 and setting a Python exception. The correct way to check for failure should be: return !(ival == -1 && PyErr_Occurred());

Part of #31424

this is my first PR here; I just wanted to get the flow down of contributing here before making any larger changes :)

AI Disclosure

I used Claude Code to help understand the codebase. The fix itself is a one-character change I applied.

PR checklist

@QuLogic QuLogic added this to the v3.11.0 milestone Apr 23, 2026
Comment thread src/_enums.h
value = decltype(value)(ival); \
Py_DECREF(tmp); \
return !(ival == -1 && !PyErr_Occurred()); \
return !(ival == -1 && PyErr_Occurred()); \
Copy link
Copy Markdown
Member

@story645 story645 Apr 23, 2026

Choose a reason for hiding this comment

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

Kinda think return (ival !=-1 || !PyErr_Occurred()); is more readable - is there a reason we can't do this?

@ksunden ksunden modified the milestones: v3.11.0, v3.10.9 Apr 23, 2026
@ksunden ksunden merged commit b39d992 into matplotlib:main Apr 23, 2026
41 of 42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants