Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #11706

Re: Why no warnings when re-assigning builtin names?

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ethan@stoneleaf.us>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python.': 0.04; 'over,': 0.05; 'sys': 0.05; 'builtins': 0.07; 'something,': 0.07; 'subject:when': 0.07; 'used.': 0.07; 'python': 0.08; '>>>>': 0.09; 'ah,': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; 'oh,': 0.09; 'received:gator410.hostgator.com': 0.09; '~ethan~': 0.09; 'ability,': 0.16; 'certainly.': 0.16; 'code?': 0.16; 'it".': 0.16; 'question)': 0.16; 'received:72.11': 0.16; 'received:72.11.125': 0.16; 'received:72.11.125.166': 0.16; 'runtime.': 0.16; 'subject:builtin': 0.16; 'wrote:': 0.16; '>>>': 0.18; 'header:In-Reply-To:1': 0.22; 'expect': 0.25; "i'm": 0.27; 'function': 0.27; 'invalid': 0.28; 'modify': 0.28; 'bit': 0.28; 'import': 0.28; 'possible?': 0.29; 'sorry,': 0.29; 'specifically': 0.29; 'environment': 0.29; 'example': 0.30; 'lines': 0.30; 'can.': 0.30; 'get.': 0.30; 'strings,': 0.30; 'class': 0.30; 'subject:?': 0.31; "didn't": 0.31; 'developers': 0.32; "isn't": 0.33; 'it.': 0.33; 'actually': 0.33; "can't": 0.33; 'too': 0.33; 'to:addr :python-list': 0.33; 'instead': 0.33; 'header:User-Agent:1': 0.34; 'things': 0.34; "we're": 0.34; 'do?': 0.34; 'stands': 0.34; 'rather': 0.35; 'speaking': 0.35; 'post': 0.36; 'but': 0.37; 'something': 0.37; 'especially': 0.37; 'open': 0.37; 'could': 0.38; 'steven': 0.38; 'subject:: ': 0.39; 'option': 0.39; "there's": 0.39; 'why': 0.39; 'to:addr:python.org': 0.39; 'case': 0.39; "it's": 0.40; 'more': 0.60; 'easily': 0.61; 'your': 0.61; 'custom': 0.61; 'received:websitewelcome.com': 0.64; 'mortal': 0.67; 'received:184': 0.67; 'proud': 0.70; 'imagine': 0.71; 'soon': 0.72; 'certainty.': 0.84; 'darn': 0.84; 'sin.': 0.84; 'tomorrow.': 0.84; 'whatever,': 0.84; 'fish': 0.91; 'received:gateway04.websitewelcome.com': 0.91; 'readily': 0.93; 'absolutely': 0.98
Date Wed, 17 Aug 2011 11:13:30 -0700
From Ethan Furman <ethan@stoneleaf.us>
User-Agent Thunderbird 1.5.0.10 (Windows/20070221)
MIME-Version 1.0
To python-list@python.org
Subject Re: Why no warnings when re-assigning builtin names?
References <BB13E4C4D649234F84A01F6DF64BB87F076AD0CE@ccs-ex01.coldstorage.com> <mailman.22.1313446504.27778.python-list@python.org> <4e49c89a$0$30001$c3e8da3$5496439d@news.astraweb.com> <mailman.34.1313464992.27778.python-list@python.org> <4e49fcd7$0$29974$c3e8da3$5496439d@news.astraweb.com> <slrnj4l8ng.1pqc.usenet-nospam@guild.seebs.net> <4e4b1242$0$29966$c3e8da3$5496439d@news.astraweb.com> <slrnj4mckr.2jq7.usenet-nospam@guild.seebs.net> <4e4b7898$0$29974$c3e8da3$5496439d@news.astraweb.com> <slrnj4ns32.clc.usenet-nospam@guild.seebs.net> <mailman.137.1313601591.27778.python-list@python.org> <slrnj4nv01.fc5.usenet-nospam@guild.seebs.net>
In-Reply-To <slrnj4nv01.fc5.usenet-nospam@guild.seebs.net>
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 - 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 mail.admailinc.com ([192.168.10.136]) [72.11.125.166]:4145
X-Source-Auth ethan+stoneleaf.us
X-Email-Count 3
X-Source-Cap dG9idWs7dG9idWs7Z2F0b3I0MTAuaG9zdGdhdG9yLmNvbQ==
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.141.1313603828.27778.python-list@python.org> (permalink)
Lines 56
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1313603828 news.xs4all.nl 23870 [2001:888:2000:d::a6]:49603
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:11706

Show key headers only | View raw


Seebs wrote:
> On 2011-08-17, Ethan Furman <ethan@stoneleaf.us> wrote:
>> Seebs wrote:
>>> On 2011-08-17, Steven D'Aprano wrote:
>>>> Ah, well you see the thing is, this is Python. As soon as you call any
>>>> function you don't control, you no longer know what your environment is
>>>> with any certainty. For all you know, the harmless-looking function is
>>>> monkey-patching builtins like there's no tomorrow. Speaking broadly,
>>>> perhaps too broadly, we're incredibly proud of the ability to modify nearly
>>>> everything at runtime.
> 
>>>> Fortunately, while we are proud of having that ability, actually *using* it
>>>> is considered a mortal sin. We're not Ruby developers -- if you actually
>>>> monkey-patch something, especially built-ins, you can expect to be taken
>>>> outside and slapped around with a fish if you get caught.
> 
>>> Here's what I don't get.
> 
>>> If it's such a bad thing, *why is it allowed*?  Why are you proud of the
>>> ability to do something that you are never socially-allowed to do?
> 
>> Monkey-patching built-ins would be something along the lines of
> 
>>      import sys
>>      sys.modules['__builtin__'].str = my_super_string
> 
>> and is what stands you in jeopardy of being fish-slapped.  ;)
> 
>> Merely shadowing a built-in, or stdlib, or whatever, isn't monkey-patching.
> 
> Oh, I know.  I was just noticing that Steven's post is specifically talking
> about how Python users are proud of having the ability to monkey-patch.
> 
> If monkey-patching like that is a mortal sin, leads to fish-slapping, and
> so on..
> 
> Why is it possible?  Why not just reject such things as invalid code?

Well, the mortal sin part is a bit of an exaggeration -- it's more like 
you'd better have a really darn good reason to do it.  And it is 
absolutely one of my favorite parts about Python.  If I want to inject a 
custom Path class into builtins so it's readily available, and then 
change os.listdir to return it instead of normal strings, I can.  If my 
application is truly case-insensitive, I can make my own istr class and 
monkey-patch builtins so it's what is used.  Can this blow-up in my 
face?  Certainly.  But I would rather have the option open to me instead 
of being told "No, I'm sorry, you can't do that because I (developers in 
question) didn't imagine a good use case for it".

Part of the fun of Python is experimentation.  And how much fun is it to 
be told over and over, "No, you can't do that"?

As an example of something that could easily have been outlawed, but 
wasn't, check out http://stackoverflow.com/questions/7068340

~Ethan~

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Why no warnings when re-assigning builtin names? Chris Angelico <rosuav@gmail.com> - 2011-08-15 23:15 +0100
  Re: Why no warnings when re-assigning builtin names? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-08-16 11:32 +1000
    Re: Why no warnings when re-assigning builtin names? Philip Semanchuk <philip@semanchuk.com> - 2011-08-15 23:23 -0400
      Re: Why no warnings when re-assigning builtin names? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-08-16 15:15 +1000
        Re: Why no warnings when re-assigning builtin names? Philip Semanchuk <philip@semanchuk.com> - 2011-08-16 10:13 -0400
          Re: Why no warnings when re-assigning builtin names? rantingrick <rantingrick@gmail.com> - 2011-08-16 08:44 -0700
            Re: Why no warnings when re-assigning builtin names? Andrew Berg <bahamutzero8825@gmail.com> - 2011-08-16 12:23 -0500
        Re: Why no warnings when re-assigning builtin names? Chris Angelico <rosuav@gmail.com> - 2011-08-16 16:12 +0100
        Re: Why no warnings when re-assigning builtin names? Ethan Furman <ethan@stoneleaf.us> - 2011-08-16 08:41 -0700
          Re: Why no warnings when re-assigning builtin names? Seebs <usenet-nospam@seebs.net> - 2011-08-16 17:11 +0000
            Re: Why no warnings when re-assigning builtin names? Ethan Furman <ethan@stoneleaf.us> - 2011-08-16 10:48 -0700
            Re: Why no warnings when re-assigning builtin names? Tim Chase <python.list@tim.thechases.com> - 2011-08-16 13:34 -0500
        Re: Why no warnings when re-assigning builtin names? Philip Semanchuk <philip@semanchuk.com> - 2011-08-16 11:31 -0400
        Re: Why no warnings when re-assigning builtin names? Philip Semanchuk <philip@semanchuk.com> - 2011-08-16 11:38 -0400
        Re: Why no warnings when re-assigning builtin names? Ethan Furman <ethan@stoneleaf.us> - 2011-08-16 09:19 -0700
          Re: Why no warnings when re-assigning builtin names? Seebs <usenet-nospam@seebs.net> - 2011-08-16 17:11 +0000
            Re: Why no warnings when re-assigning builtin names? Ethan Furman <ethan@stoneleaf.us> - 2011-08-16 10:43 -0700
              Re: Why no warnings when re-assigning builtin names? Seebs <usenet-nospam@seebs.net> - 2011-08-16 18:56 +0000
                Re: Why no warnings when re-assigning builtin names? Terry Reedy <tjreedy@udel.edu> - 2011-08-16 19:32 -0400
                Re: Why no warnings when re-assigning builtin names? Seebs <usenet-nospam@seebs.net> - 2011-08-16 23:49 +0000
                Re: Why no warnings when re-assigning builtin names? Chris Angelico <rosuav@gmail.com> - 2011-08-17 01:02 +0100
                Re: Why no warnings when re-assigning builtin names? Seebs <usenet-nospam@seebs.net> - 2011-08-17 01:35 +0000
                Re: Why no warnings when re-assigning builtin names? Chris Angelico <rosuav@gmail.com> - 2011-08-17 08:27 +0100
                Re: Why no warnings when re-assigning builtin names? Seebs <usenet-nospam@seebs.net> - 2011-08-17 16:33 +0000
                Re: Why no warnings when re-assigning builtin names? Terry Reedy <tjreedy@udel.edu> - 2011-08-16 22:10 -0400
            Re: Why no warnings when re-assigning builtin names? Chris Angelico <rosuav@gmail.com> - 2011-08-16 19:23 +0100
        Re: Why no warnings when re-assigning builtin names? Tim Chase <python.list@tim.thechases.com> - 2011-08-16 11:10 -0500
        Re: Why no warnings when re-assigning builtin names? Philip Semanchuk <philip@semanchuk.com> - 2011-08-16 12:32 -0400
          Re: Why no warnings when re-assigning builtin names? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-08-17 11:29 +1000
            Re: Why no warnings when re-assigning builtin names? Philip Semanchuk <philip@semanchuk.com> - 2011-08-16 22:16 -0400
        Re: Why no warnings when re-assigning builtin names? Ethan Furman <ethan@stoneleaf.us> - 2011-08-16 10:07 -0700
        Re: Why no warnings when re-assigning builtin names? Seebs <usenet-nospam@seebs.net> - 2011-08-16 17:11 +0000
          Re: Why no warnings when re-assigning builtin names? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-08-17 10:58 +1000
            Re: Why no warnings when re-assigning builtin names? Seebs <usenet-nospam@seebs.net> - 2011-08-17 03:17 +0000
              Re: Why no warnings when re-assigning builtin names? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-08-17 18:15 +1000
                Re: Why no warnings when re-assigning builtin names? Seebs <usenet-nospam@seebs.net> - 2011-08-17 16:33 +0000
                Re: Why no warnings when re-assigning builtin names? Ethan Furman <ethan@stoneleaf.us> - 2011-08-17 10:36 -0700
                Re: Why no warnings when re-assigning builtin names? Seebs <usenet-nospam@seebs.net> - 2011-08-17 17:36 +0000
                Re: Why no warnings when re-assigning builtin names? Ethan Furman <ethan@stoneleaf.us> - 2011-08-17 11:13 -0700
                Re: Why no warnings when re-assigning builtin names? Seebs <usenet-nospam@seebs.net> - 2011-08-17 18:09 +0000
                Re: Why no warnings when re-assigning builtin names? Chris Angelico <rosuav@gmail.com> - 2011-08-17 18:42 +0100
                Re: Why no warnings when re-assigning builtin names? Seebs <usenet-nospam@seebs.net> - 2011-08-17 17:38 +0000
                Re: Why no warnings when re-assigning builtin names? Chris Angelico <rosuav@gmail.com> - 2011-08-17 19:02 +0100
                Re: Why no warnings when re-assigning builtin names? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-08-18 10:36 +1000
            Re: Why no warnings when re-assigning builtin names? Chris Angelico <rosuav@gmail.com> - 2011-08-17 08:34 +0100
        RE: Why no warnings when re-assigning builtin names? "Gerrat Rickert" <grickert@coldstorage.com> - 2011-08-16 13:15 -0400
        Re: Why no warnings when re-assigning builtin names? Terry Reedy <tjreedy@udel.edu> - 2011-08-16 19:29 -0400
        Re: Why no warnings when re-assigning builtin names? Philip Semanchuk <philip@semanchuk.com> - 2011-08-16 20:18 -0400
        Re: Why no warnings when re-assigning builtin names? Terry Reedy <tjreedy@udel.edu> - 2011-08-16 22:15 -0400
        Re: Why no warnings when re-assigning builtin names? Philip Semanchuk <philip@semanchuk.com> - 2011-08-16 22:51 -0400
        RE: Why no warnings when re-assigning builtin names? "Gerrat Rickert" <grickert@coldstorage.com> - 2011-08-17 09:30 -0400
    Re: Why no warnings when re-assigning builtin names? Chris Angelico <rosuav@gmail.com> - 2011-08-16 09:16 +0100
  Re: Why no warnings when re-assigning builtin names? Chris Torek <nospam@torek.net> - 2011-08-31 21:30 +0000
    Re: Why no warnings when re-assigning builtin names? Seebs <usenet-nospam@seebs.net> - 2011-08-31 21:57 +0000

csiph-web