[Python-ideas] Quick idea: defining variables from functions that take the variable name
Sjoerd Job Postmus
sjoerdjob at sjoerdjob.com
Fri Jun 3 04:26:00 EDT 2016
> On 3 Jun 2016, at 09:55, Piotr Duda <duda.piotr at gmail.com> wrote:
>
> 2016-06-03 9:45 GMT+02:00 Paul Moore <p.f.moore at gmail.com>:
>>> On 3 June 2016 at 07:05, Steven D'Aprano <steve at pearwood.info> wrote:
>>> I'm objecting to it because it needlessly doubles the number of
>>> callables needed. Instead of there being one namedtuple function, you
>>> need two: a single parameter version, and a wrapper that performs
>>> whatever magic is needed to crowbar the multiple parameter version into
>>> the constraint of a single parameter version.
>>
>> Thanks for clarifying your objection, I hadn't really understood what
>> you had an issue with until now.
>>
>> OK, so the question is between needing extra callables, vs a somewhat
>> "magical" process for injecting an argument.
>>
>> We still differ on which is the more acceptable answer, but I'm happy
>> to offer both up for consideration, now that the differences are
>> clear.
>
> There is also third option, return normal object that have special
> dunder method (ex. __def__), which allow set name (and maybe module
> and qualname) for object.
With the added benefit that in Python 3.something you can already emulate this for construction during class construction: in the __prepare__ of the metaclass, return a dictionary wrapper which does that.
Of course, that's also what Django does now already (in a Python 2 compatible way) from metaclass.__new__.
More information about the Python-ideas
mailing list