Skip to content

Dispatchable ABC interface not supported #22

@ccomb

Description

@ccomb

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions