[Python-ideas] Quick idea: defining variables from functions that take the variable name

Alan Cristhian alan.cristh at gmail.com
Tue May 31 12:09:05 EDT 2016


> The fundamental use-case here is "any object that needs to know its own
> name". Most objects need more than just a name.

A more general solution could be:

    def x, y, z as <expression>

Where <expression> should return a callable that accept only one argument.
So, you can do some like:

    def Type(bases, namespace):
        def get_name(name):
            return type(name, bases, namespace)
        return get_name

    def x, y, z as Type(bases, namespace)

That is a syntax sugar of:

    dummy = Type(bases, namespace)
    x = dummy("x")
    y = dummy("y")
    z = dummy("z")



2016-05-31 12:27 GMT-03:00 David Mertz <mertz at gnosis.cx>:

> This is bikeshedding a bit, but a keyword that looks good to me:
>
> expose Typevar as T
> expose Symbol as X
> On May 31, 2016 2:06 AM, "Paul Moore" <p.f.moore at gmail.com> wrote:
>
>> On 31 May 2016 at 09:56, Stephen J. Turnbull <stephen at xemacs.org> wrote:
>> > I know you don't think a keyword works for you, but
>> > either the recently reraised "def <name> = <type-expr>" or perhaps
>> > "type <name>: <type-expr>" make more sense to me right out of the box.
>>
>> I was thinking along the lines of "name <some_keyword> callable",
>> which I don't think works because it needs some "punctuation" to
>> separate the name from the callable.
>>
>> But "def name = callable" (or some other preceding keyword combined
>> with =) might work. I don't like "type" though, as the point here (I
>> thought - see below) is to come up with a construct useful for more
>> than just types.
>>
>> > I'm +1 for stopping the bikeshedding until we've all got a lot of
>> > stubfile reading under our belts.
>>
>> If this was simply about type definitions, I'd agree. But I thought
>> the point of Guido's post was that having seen two examples (TypeVar
>> and Symbol) is there a more general approach that might cover these
>> two cases as well as others? So just looking at the problem in terms
>> of stub files isn't really the point here.
>>
>> Paul
>> _______________________________________________
>> Python-ideas mailing list
>> Python-ideas at python.org
>> https://mail.python.org/mailman/listinfo/python-ideas
>> Code of Conduct: http://python.org/psf/codeofconduct/
>>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160531/68110542/attachment.html>


More information about the Python-ideas mailing list