Why no warnings when re-assigning builtin names?

Seebs usenet-nospam at seebs.net
Wed Aug 17 19:36:08 CEST 2011

On 2011-08-17, Ethan Furman <ethan at 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?

Copyright 2011, all wrongs reversed.  Peter Seebach / usenet-nospam at seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.

More information about the Python-list mailing list