Skip to content

This decorator returns a "Callable" not a "FunctionType" #770

Answered by KotlinIsland
dhruvinsh asked this question in Q&A
Discussion options

You must be logged in to vote

thaks so much for reaching out, and sorry that you have run into a confusing situation.

tl;dr you are seeing #690

in this situation, basedmypy is warning you about an ambiguous situation regarding functions in classes:

class Call:
    def __call__(self, a: A):
        pass

def decorate(c: Callable[[A], None]) -> Callable[[A], None]:
    return Call()
    
class A:
    @decorate
    def foo(self):
        pass
A().foo()  # runtime error: Call.__call__() missing 1 required positional argument: 'a'

the intent of this error, is that a non-function Callable appears where a 'method' would normally be expected.

functions bind their first parameter, plain callables don't

unfortunately, functools…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@dhruvinsh
Comment options

@KotlinIsland
Comment options

Answer selected by KotlinIsland
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants