Skip to content

Intersection Makes method-types generic #51

Open

Description

@erezinman

I wish to indicate that a function of mine accepts both an "orphaned method" and a "method" of a some class. Because this is a generic method wrapper, I need it to have known param-spec and return types. For now I use:


UnwrappedClassMethod = Callable[Concatenate['Class', P], RT]
ClassMethod = Callable[P, RT]

def execute_class_method(method: Union[UnwrappedClassMethod[P, RT], ClassMethod[P,RT],
                                       *args: P.args, **kwrags: P.kwargs) -> RT: ...

What I do want is:

ClassMethod = Intersect[Callable[P, RT], MethodType]

To indicate this is both callable, and has a __func__ and __self__ attributes. Protocols can be used here, but it's and less coherent to other people.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions