The following code works, but I fell like I shouldn't have to write it: def test_transaction(self, the_client): [...] transaction: Transaction = transactions.filter([...]).first() # NOTE: this is stupid and unnecessary just to satisfy mypy. # the next expect() will bail if this test is true, # so this if statement is completely superfluous if transaction is None: raise AssertionError("missing transaction") # I want to tell mypy this works like the above if statement expect(transaction).not_to(be_none()) # if the if statement above isn't there, it tells me # None | Transaction doesn't have the property "client" expect(transaction.client).to(equal(the_client)) [...] Is there an easier way to do this that will satisy mypy? I have 1000+ tests like this and I don't want to add 2000+ more lines of completely unnecessary, useless code just to make a freaking code checker happy. I have the django and drf stubs installed. Continue reading...