A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2004-March/043478.html below:

[Python-Dev] PEP 318 - posting draft

[Python-Dev] PEP 318 - posting draftBob Ippolito bob at redivi.com
Wed Mar 24 15:53:04 EST 2004
On Mar 24, 2004, at 1:32 PM, Guido van Rossum wrote:

>>>> I think this use case is rather elegant:
>>>>
>>>> def singleton(cls):
>>>>     return cls()
>>>>
>>>> class Foo [singleton]:
>>>>     ...
>>
>>     Guido> And how would this be better than
>>
>>     Guido>     class Foo(singleton):
>>     Guido>         ...
>>
>>     Guido> (with a suitable definition of singleton, which could just 
>> be
>>     Guido> 'object' AFAICT from your example)?
>>
>> "Better"?  I don't know.  Certainly different.  In the former, Foo 
>> gets
>> bound to a class instance.  In the latter, it would be a separate 
>> step which
>> you omitted:
>>
>>     class Foo(singleton):
>>         ...
>>     Foo = Foo()
>
> Ok, so the metaclass would have to be a little different, but this can
> be done with metaclasses.  (But I think that this in particular
> example, declaring the instance through the class is merely
> confusing. :-)

Fine, but try doing singleton *and something else that needs a 
metaclass* without first composing every 
metaclass-supported-class-decorator combination you want to use a 
priori.

-bob


More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4