A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2009-March/086712.html below:

[Python-Dev] ABCs and MRO

[Python-Dev] ABCs and MRO [Python-Dev] ABCs and MROPaul 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

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4