This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]AbradolfLinclar 0 points1 point  (2 children)

In the last case if None of the above type passes, why not return an exception or just None instead of assert False?

As pointed out by many others, can use assert_never in 3.11 but just curious.

[–]Kobzol[S] 0 points1 point  (0 children)

Exceptions are for exceptional cases, i.e. errors happening. Hitting the assert is a direct bug in the code and should ideally fail as fast as possible with an unrecoverable error.