[Python-ideas] Importing public symbols and simultainiously privatizing them, is too noisy

Steven D'Aprano steve at pearwood.info
Wed Mar 16 22:10:13 EDT 2016


On Wed, Mar 16, 2016 at 06:52:13PM -0700, Rick Johnson wrote:
> On Wednesday, March 16, 2016 at 7:43:05 PM UTC-5, Steven D'Aprano wrote:

> > Out of the infinite number of names that x could be
> > imported as (import x as y etc) what's so special about _x
> > that it deserves a short-cut?
> 
> Not exactly sure what your saying here, but, i'll fancy a
> guess... 

"import as" is a general mechanism for renaming variables on import. 
When can use any new name we like:

from module import x as a
from module import x as b
from module import x as c
...
from module import x as z

and all get treated the same way: whatever name you want to rename x as, 
you use the same, standard syntax: "import oldname as newname".

But you are suggesting a new keyword, or other built-in functionality, 
to handle *one special case only*:

import oldname as _oldname


The Zen of Python tells us about special cases:

Special cases aren't special enough to break the rules.


Of course, the Zen of Python isn't absolute. If there really is 
something special enough to justify a special case, then the "Special 
cases" koan doesn't apply. Hence my question: why is _oldname so special 
that it deserves special syntax?

I'm not questioning that it's special. I'm questioning what makes it 
sufficiently special that it overrides the design principles espoused by 
the Zen of Python.



-- 
Steven


More information about the Python-ideas mailing list