Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'context': 0.04; 'subject:when': 0.07; 'variable,': 0.07; 'builtin': 0.09; 'either.': 0.09; 'rename': 0.09; 'am,': 0.12; 'broken': 0.12; '16,': 0.15; "'file')": 0.16; '-tkc': 0.16; '11:12': 0.16; 'common.': 0.16; 'cryptic': 0.16; 'diagnosing': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'message- id:@tim.thechases.com': 0.16; 'received:70.251': 0.16; 'received:dsl.rcsntx.swbell.net': 0.16; 'received:rcsntx.swbell.net': 0.16; 'received:swbell.net': 0.16; 'remedied': 0.16; 'semanchuk': 0.16; 'subject:builtin': 0.16; 'symptoms': 0.16; 'trap': 0.16; 'zipfile': 0.16; 'cc:addr:python- list': 0.16; 'wrote:': 0.16; '(i.e.': 0.17; '(which': 0.19; 'wrote': 0.20; '(like': 0.21; 'trying': 0.21; 'cc:2**0': 0.22; 'header:In-Reply-To:1': 0.22; 'produces': 0.23; 'tool,': 0.23; 'aug': 0.24; 'library.': 0.24; 'code': 0.25; 'creating': 0.25; 'described': 0.28; 'cc:addr:python.org': 0.30; 'fairly': 0.30; 'module': 0.30; 'accidentally': 0.30; 'easier.': 0.30; 'modules': 0.31; 'subject:?': 0.31; 'chris': 0.32; 'usually': 0.32; 'it.': 0.33; 'actually': 0.33; 'there': 0.33; "i've": 0.34; 'done': 0.34; 'header:User-Agent:1': 0.34; 'describe': 0.34; 'setting': 0.34; 'things': 0.34; 'duplicate': 0.34; 'occurs': 0.34; 'weird': 0.34; 'problem.': 0.36; 'file': 0.36; 'issue': 0.36; 'bigger': 0.37; 'using': 0.37; 'several': 0.37; 'but': 0.37; 'something': 0.37; 'could': 0.38; 'subject:: ': 0.39; 'called': 0.40; 'where': 0.40; 'extremely': 0.40; 'easily': 0.61; 'your': 0.61; '"oh,': 0.84; '10:31': 0.84; 'deliberate': 0.84 Date: Tue, 16 Aug 2011 11:10:46 -0500 From: Tim Chase User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.18) Gecko/20110616 Thunderbird/3.1.11 MIME-Version: 1.0 To: Philip Semanchuk Subject: Re: Why no warnings when re-assigning builtin names? References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <2A3EB048-1F10-46E8-973F-9BBD303E7B9F@semanchuk.com> <85D7AC88-68CA-4913-8A60-5DDCDA9F2107@semanchuk.com> In-Reply-To: <85D7AC88-68CA-4913-8A60-5DDCDA9F2107@semanchuk.com> Content-Type: text/plain; charset=ISO-8859-1; 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 - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com X-Source: X-Source-Args: X-Source-Dir: Cc: Lista-Comp-Lang-Python list X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 40 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1313511055 news.xs4all.nl 23911 [2001:888:2000:d::a6]:34965 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:11573 On 08/16/2011 10:31 AM, Philip Semanchuk wrote: > On Aug 16, 2011, at 11:12 AM, Chris Angelico wrote: >> There are several types of shadowing: >> >> 1) Deliberate shadowing because you want to change the behavior of the >> name. Extremely rare. >> 2) Shadowing simply by using the name of an unusual builtin (like >> 'file') in a context where you never use it. Very common. >> 3) Unintentional shadowing where you create a variable, but then >> intend to use the builtin. This is the only one that's a >> problem. > > Yes, but before you get to #3 you have to go through #2. The > way I see it, #2 is setting a trap, #3 is actually stepping > in it. I don't want to do either. Neither do I like working > with code that has set trap #2 for me. Chris succinctly described the times I've done shadowing. Fortunately, the shadowing done in #3 (which you appropriately describe as being a superset of #2) is fairly remedied with most editors...since it usually occurs when you have "oh, I accidentally shadowed builtin X", so you just do a global search-and-replace for all those places you shadowed X and rename it to something like "my_X" and proceed to use X as the builtin. The bigger issue I have is module shadowing which is trickier to catch and produces weird symptoms (i.e. cryptic errors). The most common one I see is creating a local module called "email.py" and then having issues when trying to use standard-library email calls which find your local email.py before they find the email.py file in the standard library. I actually wrote a tool to scan for duplicate modules in $PYTHONPATH (pretty dumb tool, could easily have broken on things like zipfile imports, DLLs, etc), but it made diagnosing the issue easier. -tkc