Replies: 1 comment 3 replies
-
That's not unreasonable. I think we once tried to make it possible to describe a module using a Protocol (can't recall if we managed that) and it could work for classes too. I have no idea how hard it would be to implement though. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a situation where I have a protocol I'd like to define which can be implemented either as instance methods in a normal object or in class methods in a class, when I don't need multiple instances. I could do this with a singleton, but Python has no problem letting me just pass in the class itself in place of an instance, as long as all the methods that would have been instance methods are made into class methods. Here's a trimmed down example showing the basic idea:
If you run this code, it works just fine. However, when running it through mypy, I get:
Any thoughts on whether something like this is possible?
Beta Was this translation helpful? Give feedback.
All reactions