Fix some missing null checks. (GH-118721)

(cherry picked from commit 7e6fcab20003b07621dc02ea78d6ea2fda500371)

Co-authored-by: Steve Dower <steve.dower@python.org>
2 files changed