Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.017 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'finally:': 0.07; 'except:': 0.09; 'try:': 0.09; 'cc:addr:python-list': 0.11; "wouldn't": 0.14; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'commit': 0.19; 'cc:addr:python.org': 0.22; 'skip:e 30': 0.24; 'cc:2**0': 0.24; '15,': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'raise': 0.29; 'tim': 0.29; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'chase': 0.31; 'maybe': 0.34; 'something': 0.35; 'done.': 0.35; 'received:google.com': 0.35; 'possible': 0.36; 'example,': 0.37; 'nov': 0.38; 'pm,': 0.38; 'back': 0.62; 'close': 0.67; 'toy': 0.84; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=D3Okty1L/zOALlti85Ncmhd/vA36PSN8vYeJIaogx1Y=; b=n5vwhNARD1/VlUjPCa94hiq7b6kLt1h0/CN5x7Whs74tGEyPBWm6gsEprg3wfmrkGp 3K9Pr+O8ALvKXUVL9/6g87b2uaSmfXUCEQmt6yTAb5RVLDaC+ozLhiHQRDsKaS5O3GK6 /oYCvrMijNjsRrcndEoxToYW9Xiv4tpO73nVsxdoZIMNLnhjMS3l7FJZg3vTUxBrsnd6 HcnMWsJtKnhQf3U0/AMAPDVCq68wAXORoNw2vjcetlyDBpl0amKq5hbT84kfhz06jm2n ONwkY0H5OlT2P2DH1V/Y6T28cgcdF3zHNABLdQTmABKlUgJUImrtnGXO8cRkSCBbRTOI M5sQ== MIME-Version: 1.0 X-Received: by 10.42.53.80 with SMTP id m16mr7519883icg.43.1416017810212; Fri, 14 Nov 2014 18:16:50 -0800 (PST) In-Reply-To: <20141114201453.16a034df@bigbox.christie.dr> References: <96c138e4-ab95-4e5f-a0c8-e696b5a926bb@googlegroups.com> <87a93wqeq3.fsf@elektro.pacujo.net> <87y4rgozgd.fsf@elektro.pacujo.net> <0cdc67f4-d9d5-4a73-91fe-7558161246af@googlegroups.com> <28e159ff-3d64-4793-9082-05cf1553c7c2@googlegroups.com> <87h9y4owgc.fsf@elektro.pacujo.net> <54669308$0$13002$c3e8da3$5496439d@news.astraweb.com> <87h9y1l3tt.fsf@elektro.pacujo.net> <87a93tl07u.fsf@elektro.pacujo.net> <20141114201453.16a034df@bigbox.christie.dr> Date: Sat, 15 Nov 2014 13:16:50 +1100 Subject: Re: I love assert From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1416017813 news.xs4all.nl 2848 [2001:888:2000:d::a6]:47707 X-Complaints-To: abuse@xs4all.nl Path: csiph.com!usenet.pasdenom.info!bete-des-vosges.org!feed.ac-versailles.fr!proxad.net!feeder1-2.proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Xref: csiph.com comp.lang.python:80801 On Sat, Nov 15, 2014 at 1:14 PM, Tim Chase wrote: > On 2014-11-15 12:48, Chris Angelico wrote: >> conn = establish_database_connection() >> try: >> do_stuff() >> finally: >> conn.rollback() > > this sounds suspiciously like you'd never actually commit. Do you > mean something like > > conn = establisth_database_connection() > try: > do_stuff(conn) > except: > conn.rollback() > raise No; I prefer to have the commit be as close as possible to the code that needs it done. So in this toy example, the commit would be inside - maybe deep inside - do_stuff(). After committing, rolling back wouldn't hurt. ChrisA