[Python-3000] Sane transitive adaptation
Nick Coghlan
ncoghlan at gmail.com
Sat Apr 8 06:45:12 CEST 2006
Nick Coghlan wrote:
> With a change in type.__call__() to check the class extension registry
> before calling cls.__new__(), the above would put us well on the way to making
> all types extensible. For example, we could make a class of our own behave
> like a dictionary, returning its keys when converted to a list, and its
> key-value pairs when converted to a dictionary:
>
> @extend(list).for_signature(MyMapping):
> def get_keys(obj)
> return obj.keys()
>
> @extend(dict).for_signature(MyMapping):
> def get_items(obj)
> return obj.items()
Oops, better make that:
@extend(list).for_signature(MyMapping):
def get_keys(obj)
return list(obj.keys())
@extend(dict).for_signature(MyMapping):
def get_items(obj)
return dict(obj.items())
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
More information about the Python-3000
mailing list