You proposed using assertions in python, which is considered code smell outside of testing.

Annoying Adam 2 months ago updated 2 months ago 0

In this post: Introduce Assertion (refactoring.guru)
The python version of the code uses "assert" keyword which is always discouraged from being used outside tests because all assertions can be easily bypassed with debugging flag.
So in production code this is a code smell in python, and instead a "raise" keyword should be used.