You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[CPyCppyy] Fix improper warning handling and support -W error
Replace deprecated [1] `PyErr_Warn()` with `PyErr_WarnEx()` and
correctly handle its return value throughout the CPyCppyy codebase.
Previously, warnings were emitted without checking for failure. When
Python is run with `"-W error"` (or equivalent filters), warnings are
promoted to exceptions, causing `PyErr_Warn*()` to return an error while
leaving an exception set. The code would then continue execution and
return a valid value, triggering errors such as:
```
SystemError: <blah ...> returned a result with an exception set
```
This change ensures that all warning calls:
- use the non-deprecated `PyErr_WarnEx()`
- properly propagate errors when warnings are turned into exceptions
Additional fixes:
- Update tests to explicitly control warning behavior using
`warnings.catch_warnings()`, avoiding unintended interaction with
global `"-W error"` settings
- Adjust tests to expect exceptions when warnings are promoted to errors
This makes CPyCppyy more compliant with CPython C API requirements and
robust under strict warning configurations.
[1] https://www.cs.auckland.ac.nz/references/python/2.7.3-docs/c-api/exceptions.html?utm_source=chatgpt.com#PyErr_Warn
0 commit comments