`check` is obviously `None`. You have defined it the line before.