
Hi Clint, (this is a bit of nit-picking, but kind of supports the OPs concerns about intent) On 27.11.2014 17:01, Clint Hepner wrote:
On Thu, Nov 27, 2014 at 9:24 AM, Stefano Borini < stefano.borini@ferrara.linux.it> wrote:
On Thu, Nov 27, 2014 at 11:30:40PM +1100, Chris Angelico wrote:
You could abuse try/finally for this purpose.
try: whatever you need to do finally: my_widget.setFocus()
I thought about this solution, but I am concerned about communication of intent. Using the try communicates to a code reader that the code inside is expected to throw, which is not the case.
If there is absolutely no possibility of an exception, you don't need any special construct. Just use
whatever you need to do my_widget.setFocus()
Otherwise, you are tacitly agreeing that an exception *might* occur, so try/finally is not misleading.
Not neccessarily. try/finally can also be used to do something in all return paths: def foo(): try: return True finally: print("foo") will print foo and return True. There is no way this can throw, nevertheless try/finally can be useful if you have to do some clean up and have several return paths. regards, jwi
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/