MAINT: fix another wrong NULL check

silences cppcheck error, not a bug as the only caller checks the python
error.
Merge pull request #3838 from juliantaylor/null-fix

MAINT: fix another wrong NULL check