Do not use AssertionError for control flow
When running in optimized mode, asserts are a noop
(https://docs.python.org/3/reference/simple_stmts.html#the-assert-statement).
We don't use optimized mode in the nightlies, but apparently it happens
on the GRID (where the PYTHONOPTIMIZE
environment variable is set),
and since except AssertionError
was used in one place for control flow,
that lead to a different behaviour on the GRID.
tl;dr do not catch asserts in Python