◐ Shell
clean mode source ↗

gh-146102: Catch PyErr_NewException() failure in zlib by vstinner · Pull Request #151342 · python/cpython

Choose a reason for hiding this comment

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

This isn't strictly necessary, PyModule_AddObjectRef will return -1 if it's NULL. Looking at other modules, they also follow this pattern.

Choose a reason for hiding this comment

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

Oh you're right! I checked PyModule_AddObjectRef() documentation and it's well documented:

To be convenient, the function accepts NULL value with an exception
set. In this case, return -1 and just leave the raised exception
unchanged.