the demise of 'from foo import * and its implications?
Robin Becker
robin at jessikat.fsnet.co.uk
Sun Mar 4 20:00:07 EST 2001
In article <mailman.983746566.27513.python-list at python.org>, Jeremy
Hylton <jeremy at alum.mit.edu> writes
>>>>>> "RB" == Robin Becker <robin at jessikat.fsnet.co.uk> writes:
>
> RB> my preference would be that statements legal in one context
> RB> should be legal in another where they make sense. I cannot see
> RB> how using import * or eval etc in nested scopes is somehow
> RB> obviously bad or different from the same usage in non-nested
> RB> scopes. The fact that the prohibition comes from making things
> RB> easier for the compiler adds to my confusion.
>
>Using import * in function's is asking for trouble, because it makes
>it impossible for someone reading the code to know what a variable
>refers to. Consider this hypothetical bit of code:
>
> from string import *
>
> def f(x):
> from amodule import *
> return strip(x)
>
....
doesn't from foo import * make things hard to locate at the global level
as well? exec/eval/import can always do this surely.
This is not an argument against this particular usage alone.
>
>One other thing you're confused about is that the prohibition comes
>from making things easier for the compiler. That's bunk. The
>prohibition comes because there is no reasonable and intuitive
>semantics for these features in the presence of nested scopes. When
>the issue first came up on python-dev, two seasoned Python programmers
>explained what the obvious semantics where. They chose completely
>opposite semantics. There's just no sensible meaning to assign to
>this kind of code in most cases.
>
>Jeremy
>
--
Robin Becker
More information about the Python-list
mailing list