[Python-ideas] Proposal for special name and qualname symbols

Stephen J. Turnbull stephen at xemacs.org
Tue Jun 14 02:39:56 EDT 2016


 > On Jun 11, 2016, at 05:00 PM, Barry Scott wrote:
 > 
 > >What is the behavour in this case:
 > >
 > >   mydict[ index ] = Record( __LHS__ )

I can't imagine why that would ever come up.  More likely would be

    mydict = { name : Record[name] for name in standard_symbol_names }

and the whole issue is just gone, this is TOOWTDI for such iterative
cases.  It's only when you want to inject a name (such as "mydict"
itself) into a namespace normally maintained by the compiler that you
need this.

Barry Warsaw writes:

 > That's a good question.  How insane/useless would it be to return
 > in this case the string "mydict[ index ]"?

Given the assumption that this kind of anaphorism is Pythonic at all,
it would either be that or a canonical flattening of the AST.  It
looks quite useless to me.

But IMO this is unacceptably ugly given that its use cases are so
small.  A dunder keyword that is used by design even in main programs?
C'mon, Barry, you can't mean you're going to litter Mailman code with
this!

I don't like (-0.9) Steven d'Aprano's "->" operator either, but it's
the best of a bad lot so far.  Note that it can't be used iteratively
either unless its signature is changed from <id> -> <constructor> to
<str> -> <constructor>, so that instead of writing

    x -> Symbol()

you'd write

    'x' -> Symbol()

(thus instead of reading the name of an identifier from the namespace
and passing the string to Symbol, it would find or inject an
identifier with that name in the namespace, and assign the value of
the RHS to it).  Then you could write things like

    for name in standard_symbol_names:
        name -> Symbol()

which I don't like but I suspect advocates will.

Steve


More information about the Python-ideas mailing list