If there's some user behavior that could result in these assert statements getting triggered, then I recommend changing these to some more informative RuntimeError with a message saying what went wrong.