[Python-Dev] ABCs and MRO
Paul Moore
p.f.moore at gmail.com
Wed Mar 4 14:17:13 CET 2009
2009/3/3 Jeffrey Yasskin <jyasskin at gmail.com>:
> Unfortunately, I think overloading functions on Number or Iterable
> would be really useful, and constraining it to only look at base
> classes would be unfortunate.
That could well be the case. So the question is, I guess, how would
you write such a function now? Because you could always continue to
write it like that, but make it generic for the other special cases
you didn't think of:
@simplegeneric
def foo(x, y):
if isinstance(x, Iterable):
do iterable processing
else:
do standard base processing
@foo.register(int)
def foo_int(x, y):
do int processing
It's unfortunate that you have to cover it in the base processing, but
certainly no worse than at present.
Paul.
More information about the Python-Dev
mailing list