Throw python_error if the call returns nullptr.
It's necessary to throw an exception so that PyWarningHandler
knows that there is already an exception and it properly
propagates it.
I need to think about how to lint for this situation in the
future. I also need to work out how to test this fix (my
local repro is fixed after this change).
Fixes https://github.com/pytorch/pytorch/issues/74334
Signed-off-by: Edward Z. Yang <ezyangfb.com>
Pull Request resolved: https://github.com/pytorch/pytorch/pull/74357
Approved by: https://github.com/anjali411