According to the documentation:
https://docs.python.org/3/reference/compound_stmts.html#the-try-statement
It is an expected behavior as:
If the
finally
clause executes areturn
,break
orcontinue
statement, the saved exception is discarded:
def f():
... try:
... 1/0
... finally:
... return 42
...
>>> f()
42