Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!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; 'plenty': 0.03; 'memory.': 0.05; 'warnings': 0.05; 'behavior,': 0.07; 'builtins': 0.07; 'subject:when': 0.07; 'worse': 0.07; 'python': 0.08; '>>>>': 0.09; '__future__': 0.09; 'builtin': 0.09; 'deliberately': 0.09; 'highlight': 0.09; "person's": 0.09; 'examples': 0.11; 'am,': 0.12; 'def': 0.15; 'library': 0.15; '16,': 0.15; 'argument': 0.15; 'case.': 0.15; 'heavily': 0.15; 'useful,': 0.15; '(absolute': 0.16; '*my*': 0.16; 'builtins.': 0.16; 'confusing.': 0.16; 'contrary,': 0.16; 'directive': 0.16; 'docs.': 0.16; 'fits': 0.16; 'grep': 0.16; 'highlighting': 0.16; "isn't.": 0.16; 'n00bs': 0.16; 'newcomers': 0.16; 'objects?': 0.16; 'philosophy.': 0.16; 'received:mindspring.com': 0.16; 'safe,': 0.16; 'semanchuk': 0.16; 'subject:builtin': 0.16; 'sure,': 0.16; 'versus': 0.16; 'x-mailer:apple mail (2.1084)': 0.16; 'wrote:': 0.16; "wouldn't": 0.17; 'language': 0.17; '>>>': 0.18; 'example.': 0.18; 'interesting.': 0.18; 'issue,': 0.18; "they've": 0.18; 'trying': 0.21; 'compared': 0.21; 'detect': 0.21; 'pointed': 0.21; 'header :In-Reply-To:1': 0.22; 'cheers': 0.23; 'tue,': 0.23; "one's": 0.23; 'replacing': 0.23; 'pm,': 0.24; 'variable': 0.24; 'aug': 0.24; "python's": 0.24; 'times,': 0.24; 'do,': 0.25; 'code': 0.25; 'code.': 0.26; "i'm": 0.27; 'fact': 0.27; 'code,': 0.28; 'all,': 0.28; 'raise': 0.28; 'random': 0.28; 'described': 0.28; 'import': 0.28; 'pass': 0.29; 'script.': 0.29; 'theoretical': 0.29; 'looks': 0.29; '(and': 0.29; "won't": 0.29; 'example': 0.30; 'not.': 0.30; 'times.': 0.30; 'accidentally': 0.30; 'agreed.': 0.30; 'differently': 0.30; 'harm': 0.30; 'remains': 0.30; 'class': 0.30; 'produced': 0.31; 'subject:?': 0.31; 'version': 0.32; 'chris': 0.32; 'about.': 0.32; 'cases': 0.32; 'certainly': 0.32; 'used,': 0.32; 'received:24': 0.32; 'objects': 0.32; 'comment': 0.32; 'source': 0.33; 'agree': 0.33; "isn't": 0.33; 'sort': 0.33; 'probably': 0.33; "can't": 0.33; 'there': 0.33; 'to:addr:python- list': 0.33; "i've": 0.34; 'on,': 0.34; 'done': 0.34; 'idea': 0.34; 'all.': 0.34; "we're": 0.34; 'apply': 0.35; 'trouble': 0.35; 'anything': 0.36; 'charset:us-ascii': 0.36; 'file': 0.36; 'doing': 0.36; 'issue': 0.36; 'useful': 0.36; 'things,': 0.37; 'further': 0.64; 'ever': 0.65; 'cost': 0.65; 'taking': 0.66; 'enable': 0.67; 'making': 0.67; 'safe': 0.69; 'anything,': 0.73; 'learned': 0.73; 'protecting': 0.73; 'average': 0.77; '"we\'re': 0.84; 'bitten': 0.84; 'contributors': 0.84; 'credibility': 0.84; 'individual.': 0.84; 'masking': 0.84; 'received:69.73': 0.84; 'reflection': 0.84; 'sacred': 0.84; 'warning.': 0.84; 'dozens': 0.91; 'many,': 0.93 Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Apple Message framework v1084) Subject: Re: Why no warnings when re-assigning builtin names? From: Philip Semanchuk In-Reply-To: <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> Date: Tue, 16 Aug 2011 10:13:36 -0400 Content-Transfer-Encoding: quoted-printable References: <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> To: Lista-Comp-Lang-Python list X-Mailer: Apple Mail (2.1084) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - deimos.nocdirect.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - semanchuk.com 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: 150 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1313504028 news.xs4all.nl 23977 [2001:888:2000:d::a6]:48549 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:11553 On Aug 16, 2011, at 1:15 AM, Steven D'Aprano wrote: > On Tue, 16 Aug 2011 01:23 pm Philip Semanchuk wrote: >=20 >>=20 >> On Aug 15, 2011, at 9:32 PM, Steven D'Aprano wrote: >>=20 >>> On Tue, 16 Aug 2011 08:15 am Chris Angelico wrote: >>>=20 >>>> If you want a future directive that deals with it, I'd do it the = other >>>> way - from __future__ import mask_builtin_warning or something - so >>>> the default remains as it currently is. But this may be a better = job >>>> for a linting script. >>>=20 >>> Agreed. It's a style issue, nothing else. There's nothing worse = about: >>>=20 >>> def spam(list): >>> pass >>>=20 >>> compared to >>>=20 >>> class thingy: pass >>>=20 >>> def spam(thingy): >>> pass >>>=20 >>> Why should built-ins be treated as more sacred than your own = objects? >>=20 >> Because built-ins are described in the official documentation as = having a >> specific behavior, while my objects are not. >=20 > *My* objects certainly are, because I write documentation for my code. = My > docs are no less official than Python's docs. I'm sure they are no less official to you. But you are you, and then = there's...everyone else. =3D)=20 I (and I think most people) give far more credibility to the Python docs = than to the documentation of an individual. That's not a reflection on = you, it reflects the limits of one person's ability versus = organizationally produced docs which are heavily used, discussed, and = have been iteratively developed over many years.=20 > Sometimes shadowing is safe, sometimes it isn't.=20 "Sometimes X is safe and sometimes it isn't" can be said of many, many = things, from taking a walk down the street to juggling with knives. But = it has little to do with whether or not Python should issue a warning in = the specific case we're talking about. > A warning that is off by default won't help the people who need it, = because > they don't know enough to turn the warning on. I agree that it wouldn't help the people who need it most (absolute raw = newcomers). But you're asserting that once one learned the incantation = to enable the theoretical warning we're discussing, one would have = graduated to a level where it's no longer useful. That's not the case. = There's a lot of ground to cover between "newcomer who has learned about = a particular warning" and "coder who regularly shadows builtins on = purpose".=20 I am an example. I know enough to turn the theoretical warning on, and I = would if I could. I have never shadowed a builtin deliberately. I've = done it accidentally plenty of times. There are 84 builtins in my = version of Python and I don't have them all memorized. The fact that my = editor colors them differently is the only thing I have to back up my = leaky memory. Not all editors are so gracious. >> Yes, it can be useful to replace some of the builtins with one's own >> implementation, and yes, doing so fits in with Python's "we're all >> consenting adults" philosophy. But replacing (shadowing, masking -- = call >> it what you will) builtins is not everyday practice. On the contrary, = as >> the OP Gerrat pointed out, it's most often done unwittingly by = newcomers >> to the language who have no idea that they've done anything out of = the >> ordinary or potentially confusing. >=20 > Protecting n00bs from their own errors is an admirable aim, but have = you > considered that warnings for something which may be harmless could do = more > harm than good? Isn't the whole point of a warning to highlight behavior that's not = strictly wrong but looks iffy? Sort of, "I can't be sure, but this looks = like trouble to me. I hope you know what you're doing". If we are to = eschew warnings in cases where they might be highlighting something = harmless, then we would have no warnings at all.=20 Again, shadowing builtins is not everyday practice. I have been trying = to remember if I've ever seen it done deliberately, and I can't remember = a case. Now, a comment like that is an invitation for people come out of = the woodwork with cases where they found it useful, and I would welcome = some examples as I'm sure they'd be interesting. But I think it's safe = to say that if you look at random samples of code, builtins are shadowed = unintentionally hundreds of times for every time they're shadowed = deliberately and usefully.=20 >> If a language feature is most often invoked accidentally without = knowledge >> of or regard for its potential negative consequences, then it might = be >> worth making it easier to avoid those accidents. >=20 > Perhaps. But I'm not so sure it is worth the cost of extra code to = detect > shadowing and raise a warning. After all, the average coder probably = never > shadows anything, One need look no further than the standard library to see a strong = counterexample. grep through the Python source for " file =3D". I see = dozens of examples of this builtin being used as a common variable name. = I would call contributors to the standard library above-average coders, = and we can see them unintentionally shadowing builtins many times. > and for those that do, once they get bitten *once* they > either never do it again or learn how to shadow safely. I have done it plenty of times, never been bitten (thankfully) and still = do it by accident now and again.=20 You can coerce any example to apply to an argument for or against such a = warning, but I think the general case is that Python could reduce = unintended consequences by warning when vars erase builtins. (<=3D=3D=3D = How many builtins did I use in that sentence?) Cheers Philip