CSCan Burak Sofyalıoğlu@canburaks·Nov 75557670A CPython internal question. What does g() return?pythondef g(): try: return 1 finally: return 21Quote
ESErvin Szilágyi@Ernyoke·Nov 766587e12 the return from the 'finally' block overwrites the initial return17:49 · Nov 7, 2026 · commit 66587e11QuoteReplyHide repliesCSCan Burak Sofyalıoğlu@canburaks·Nov 7Yes, exactly it returns 2. The finally return replaces the pending one, and it would silently swallow an exception too. That's why Python 3.14 now warns about return, break and continue in finally (PEP 765). https://peps.python.org/pep-0765/Python Enhancement Proposals (PEPs)PEP 765 – Disallow return/break/continue that exit a finally block | peps.python.orgThis PEP proposes to withdraw support for return, break and continue statements that break out of a finally block. This was proposed in the past by PEP 601. The current PEP is based on empirical evidence regarding the cost/benefit of this change, which ...Reply
CSCan Burak Sofyalıoğlu@canburaks·Nov 7Yes, exactly it returns 2. The finally return replaces the pending one, and it would silently swallow an exception too. That's why Python 3.14 now warns about return, break and continue in finally (PEP 765). https://peps.python.org/pep-0765/Python Enhancement Proposals (PEPs)PEP 765 – Disallow return/break/continue that exit a finally block | peps.python.orgThis PEP proposes to withdraw support for return, break and continue statements that break out of a finally block. This was proposed in the past by PEP 601. The current PEP is based on empirical evidence regarding the cost/benefit of this change, which ...Reply