Skip to content

How to accurately use a function as a type? #1935

Answered by Daverball
Dreamsorcerer asked this question in Q&A
Discussion options

You must be logged in to vote

I believe what you want is this:

class APIProtocol(Protocol):
    def under_cached_property(self, method: Callable[[Any], T]) -> under_cached_property[T]: ...

You want under_cached_property to be a generic method, rather than the entire protocol being generic.

Replies: 1 comment 2 replies

Comment options

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

@Daverball
Comment options

Answer selected by Dreamsorcerer
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