[issue5135] Expose simplegeneric function in functools module
Ryan Freckleton
report at bugs.python.org
Thu Feb 5 04:30:17 CET 2009
Ryan Freckleton <ryan.freckleton at gmail.com> added the comment:
I think that registering existing functions is an important use case, so
I vote for keeping the non-decorator version of register.
Another thing that we may want to document is that [simple]generic
doesn't dispatch based on registered abstract base classes.
>>> class A:
... pass
...
>>> class C:
... __metaclass__ = abc.ABCMeta
...
>>> C.register(A)
>>> @generic
... def pprint(obj):
... print str(obj)
...
>>> @pprint.register(C)
... def pprint_C(obj):
... print "Charlie", obj
...
>>> pprint(C())
Charlie <__main__.C object at 0xb7c5336c>
>>> pprint(A())
<__main__.A instance at 0xb7c5336c>
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5135>
_______________________________________
More information about the Python-bugs-list
mailing list