Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'attribute': 0.07; 'correct.': 0.07; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; 'received:184.172': 0.09; 'received:gator410.hostgator.com': 0.09; '~ethan~': 0.09; 'def': 0.12; 'called.': 0.16; 'naming': 0.16; "object's": 0.16; 'wrote:': 0.18; 'code.': 0.18; 'variable': 0.18; 'work,': 0.20; '>>>': 0.22; 'example': 0.22; 'header:User-Agent:1': 0.23; 'looks': 0.24; 'this:': 0.26; 'skip:" 20': 0.27; 'gets': 0.27; 'header:In-Reply- To:1': 0.27; 'point': 0.28; 'am,': 0.29; "doesn't": 0.30; 'returned': 0.30; '>>>>': 0.31; 'class': 0.32; 'noticed': 0.34; 'could': 0.34; 'connection': 0.35; 'consistent': 0.36; 'object,': 0.36; "didn't": 0.36; 'charset:us-ascii': 0.36; 'thanks': 0.36; 'to:addr:python-list': 0.38; 'realize': 0.39; 'to:addr:python.org': 0.39; 'skip:u 10': 0.60; 'ian': 0.60; 'received:173': 0.61; 'places': 0.64; 'different': 0.65; 'received:69.56': 0.68; 'jul': 0.74; 'ethan': 0.84; 'furman': 0.84; 'received:69.56.148': 0.84; '2013': 0.98 Date: Tue, 09 Jul 2013 12:19:14 -0700 From: Ethan Furman User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121010 Thunderbird/16.0.1 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Default scope of variables References: <51d4eb9c$0$29999$c3e8da3$5496439d@news.astraweb.com> <51d508ed$0$6512$c3e8da3$5496439d@news.astraweb.com> <51d5a504$0$29999$c3e8da3$5496439d@news.astraweb.com> <51DC355E.20606@stoneleaf.us> <51DC472E.3090806@stoneleaf.us> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator410.hostgator.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - stoneleaf.us X-BWhitelist: no X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: ([173.12.184.233]) [173.12.184.233]:58024 X-Source-Auth: ethan+stoneleaf.us X-Email-Count: 1 X-Source-Cap: dG9idWs7dG9idWs7Z2F0b3I0MTAuaG9zdGdhdG9yLmNvbQ== 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: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1373399640 news.xs4all.nl 15875 [2001:888:2000:d::a6]:59756 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:50271 On 07/09/2013 11:41 AM, Ian Kelly wrote: > On Tue, Jul 9, 2013 at 11:23 AM, Ethan Furman wrote: >> On 07/09/2013 09:44 AM, Ian Kelly wrote: >>> >>> On Tue, Jul 9, 2013 at 10:07 AM, Ethan Furman wrote: >>>> >>>> You could also do it like this: >>>> >>>> def updating(self): >>>> self.transaction_active = True >>>> return self >>> >>> >>> Yes, that would be simpler. I was all set to point out why this >>> doesn't work, and then I noticed that the location of the >>> "transaction_active" attribute is not consistent in the original code. >>> The DbSession class places it on self, and then the example usage >>> places it on the connection object >> >> >> It looks like DbSession has a conn object, and in the example he has >> DbSession() named as conn -- ironic, considering this is a variable scoping >> thread. ;) > > The object returned by __enter__ is the conn object, not the > DbSession, so naming it "conn" is correct. Huh. I didn't realize a different object could be returned by __enter__ without affecting which object's __exit__ gets called. Thanks for the lesson! :) -- ~Ethan~