decorators and multimethods

"Martin v. Löwis" martin at v.loewis.de
Sat Aug 7 15:51:50 CEST 2004


Michele Simionato wrote:
> def addmethod(*types):
>      """sys._getframe hack; works when the generic function is defined
>      in the globals namespace."""
>      caller_globs = sys._getframe(1).f_globals
>      def function2generic(f):
>           generic = caller_globs[f.func_name]
>           generic[types] = f
>           return generic
>      return function2generic

Couldn't you use f.func_globals to avoid the getframe hack?

Regards,
Martin



More information about the Python-list mailing list