"Michael J. Fromberger"
<[EMAIL PROTECTED]> wrote in
news:[EMAIL PROTECTED]: 

> In article <[EMAIL PROTECTED]>,
>  Rick Wotnaz <[EMAIL PROTECTED]> wrote:
> 
>> You're right that there is no necessity for such a change. I
>> was not actually talking about importing *any* module in every
>> case, but rather about importing, say, 'sys' when, for example,
>> sys.argv appeared in the code and no import had been specified.
> 
> I think I must have missed that post; I will go back and look at
> it.  However, while I'm here, how would your proposal deal with
> code like this:
> 
>    import foobar
> 
>    # ... some while later ...
>    def f( ... ):
>       ...
>       global foobar, sys
>       sys = foobar
>       ...
> 
>    # ... some while even later ...
>    f( ... )
>    sys.wallaby("Fear and loathing!")
> 
> In particular, we have no import of sys, but the name "sys" is 
> meaningful as a local alias for a different module.  I'm not
> saying you couldn't deal with this, but it rules out some of the
> more obvious ways of detecting and automatically handling this
> kind of substitution. 
> 
> Naturally, you might well ask, "why would you do such a fool
> thing?"  To this I can only respond:  "Never underestimate the
> ingenuity of fools." 
> 

I don't know that this would cause any particular problem with the 
[not exactly-]proposed method. The automagic lookup would not be 
triggered until a NameError occurred, which would not happen in this 
case. As you say, why would anyone -- at least anyone who wanted to 
rely on sys.xxx being automatically resolved -- do such a thing? Even 
under the current scheme, occluding 'sys' would prevent correct 
interpretation of sys.argv. An error is an error in either case.

Now, if 'wallaby' is not part of the foobar namespace, the automagic 
system would kick in an incorrectly import sys, and on retry would 
still not find 'wallaby' in the namespace. Much merriment would 
ensue, I'm sure. At that point, I'd want such a system to have a 
nervous breakdown and allow the debugging to begin. Whether I hand-
entered an import statement or not wouldn't change that.

-- 
rzed
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to