[issue5135] Expose simplegeneric function in functools module

Ryan Freckleton report at bugs.python.org
Wed Feb 4 03:43:21 CET 2009


Ryan Freckleton <ryan.freckleton at gmail.com> added the comment:

PJE seems to have borrowed the time machine :-). Based on the code the
register function is already a decorator:

    def register(typ, func=None):
        if func is None:
            return lambda f: register(typ, f)
        registry[typ] = func
        return func

The returned lambda is a one argument decorator. so your syntax:

    @generic_fn.register(XXX)
    def xxx_impl(xxx):
        pass

Already works. A test to validate this behavior should probably be added.

I don't mean to bikeshed, but could we call this function
functools.generic instead of functools.simplegeneric? The only reason I
can think of for keeping it simplegeneric would be to avoid a future
name clash with the Generic Function PEP and if/when that PEP get's
implemented, I would think that the functionality would live in
builtins, not functools.

----------
nosy: +ryan.freckleton

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5135>
_______________________________________


More information about the Python-bugs-list mailing list