[Python-ideas] Proposal for special name and qualname symbols
Nikolaus Rath
Nikolaus at rath.org
Wed Jun 8 15:43:41 EDT 2016
On Jun 09 2016, Steven D'Aprano <steve-iDnA/YwAAsAk+I/owrrOrA at public.gmane.org> wrote:
> This is an new thread inspired by the "Quick idea: defining variables
> from functions that take the variable name" thread.
>
> For the benefit of those who haven't read that thread, in a nutshell,
> there are some functions or classes that find it useful or necessary to
> know their own name or qualified name. At the moment, apart from a few
> special cases where the compiler does the work behind the scenes
> (function and class definitions), the only way to do this is to
> hard-code the name/qualname as a string.
>
> The classic example from the standard library is namedtuple:
>
> Record = namedtuple('Record', fields)
>
> Proposal: we introduce two special symbols to represent the name and
> qualname at any point. They can be used anywhere an identifier can be
> used.
>
> We could use special dunder names, let's say __NAME__ and __QNAME__, but
> for now I'm going to use two special symbols:
>
> @ for the unqualified bare name;
> @@ for the qualified name.
>
> The namedtuple example would become:
>
> Record = namedtuple(@, fields)
[...]
This is so similar (in both semantics and syntax) to the
Record = namedtuple($lhs, fields)
proposal that I've made several times in that thread that I am a little
offended. Either you've not read that thread all that thorougly, or you
have a rather selective memory.
Best,
-Nikolaus
--
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F
»Time flies like an arrow, fruit flies like a Banana.«
More information about the Python-ideas
mailing list