[Patches] [Patch #101215] extend 'import x as y' syntax to 'import x as y.z'
noreply@sourceforge.net
noreply@sourceforge.net
Sun, 20 Aug 2000 12:51:30 -0700
Patch #101215 has been updated.
Project:
Category: core (C code)
Status: Rejected
Summary: extend 'import x as y' syntax to 'import x as y.z'
Follow-Ups:
Date: 2000-Aug-18 05:25
By: nowonder
Comment:
I've played a bit around with the new 'import x as y' syntax and found it would be useful to be able to assign to module/class members, too.
Example from BaseHTTPServer:
import SOCKS; socket = SOCKS; del SOCKS
from socket import getfqdn; socket.getfqdn = getfqdn; del getfqdn
could become:
import SOCKS as socket # nothing new here
from socket import getfqdn as socket.getfqdn # NEW!
Assigned to Thomas for review.
-------------------------------------------------------
Date: 2000-Aug-18 11:08
By: marangoz
Comment:
Before going too far with this, here's a strong -1 without even reviewing
the patch. Playing with namespaces other than the current one is a bad
idea.
+1 on import x as y. As long as you introduce a new binding in the
current namespace, being able to alter the original name for that binding
is nice.
-1 on import x as y.z, though, because you want to introduce a binding
in a namespace which you don't own (y's namespace). For that matter,
y must exist in the current namespace and allow bindings, which is not
granted at all. Overall, this sucks <wink>. Example:
>>> y = 1
>>> import sys as y.sys
Please reject this before I see another patch update, or I'll reject it on
the first update that'll hit my mailbox <wink>.
-------------------------------------------------------
Date: 2000-Aug-18 11:28
By: twouters
Comment:
Hmm... I like the idea a bit, but it'm -1 on the approach: Special casing 'name.name' is *not* the way to go. Instead, what we can do is to allow all normal assignment expressions in the 'as <name>' so that you can do
import shelve
from myTools.cPickleFast import Pickler as shelve.Pickler
as well as
x = []
from sys import stdin as x[0], stdout as x[1], stderr as x[2]
and
class X: pass
x = X()
from sys import stdin as x.in, stdout as x.out, stderr as x.err
and even
from sys import sys.version_info as (major, minor, patchlevel, releaselevel, releaseserial)
(though you'd need the parentheses to disambiguate)
This is all possible by changing the Grammar slightly, and calling 'com_assign(c, <as-name>)' rather than 'com_addbyte(c, STORE_NAME, <as-name>)', I think. Just for laughs, I'll see if it's possible ;) It would certainly be consistent ! and it would behave exactly like
import sys
x = [sys.stdin, sys.stdout, sys.stderr]
[insert other examples]
except that sys won't be added to the local namespace.
-------------------------------------------------------
Date: 2000-Aug-19 21:37
By: twouters
Comment:
Note that I just uploaded a smaller patch that does more than this patch<wink>. If that generalization is accepted, this patch would be obsolete.
-------------------------------------------------------
Date: 2000-Aug-20 19:51
By: nowonder
Comment:
Obsolete. After seeing Thomas' version, I am -1 on this patch (which was only a hack anyway).
-------------------------------------------------------
-------------------------------------------------------
For more info, visit:
http://sourceforge.net/patch/?func=detailpatch&patch_id=101215&group_id=5470