Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dispatchable ABC interface not supported #22

Open
ccomb opened this issue Nov 8, 2015 · 1 comment
Open

Dispatchable ABC interface not supported #22

ccomb opened this issue Nov 8, 2015 · 1 comment

Comments

@ccomb
Copy link

ccomb commented Nov 8, 2015

Hi!
I've tried to create an interface similar to z3 ones, but as an ABC, and register it as the dispatchable callable without creating a separate function, so that I can write IStuff(obj) to retrieve an adapter of obj implementing IStuff. (I really liked this syntax for the lookup).

Something like:

@reg.dispatch('entity')
class IStuff(metaclass=ABCMeta):

    @abstractmethod
    def __init__(context):
        pass

    @abstractmethod
    def foobar():
        """Foobar doc"""

It doesn"t work. The first reason is that get_callable_info does not support abstract classes. It's just a matter of adding this in it (and assuming the __init__ is an abstractmethod):

if inspect.isabstract(callable):
    return get_class_init(callable), callable, False

Once this is fixed, I get another issue in register_function_by_predicate_key because the arginfo(value) is using the Dispatcher constructor instead of the decorated class constructor (the abc interface), so the signature is not the same: 'context' is not found I've not gone further.

Otherwise thanks a lot for reg, it's a very nice replacement for the zca!

@faassen
Copy link
Member

faassen commented Nov 26, 2015

Hey, thank you for reporting this issue. Sorry it took a while for me to get to it.

I'd be very welcome to see patches to make this work. We need to make it understand abcs to do so. Just a patch that contains some tests of what you'd like to work would be helpful.

Note that I went full-on for generic functions in the end in Morepath so don't use this zca style pattern.

To construct the right mro for a class that contains abcs we will need something like code I originally found in Python single dispatch logic to insert abcs in the right places in the class hierarchy. Here's a revision that contains that code still:

820055e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants