I’m pretty sure you’re looking for typing.Protocol.

On mobile, so I’ll link to docs instead of elaborating inline: https://docs.python.org/3/library/typing.html#typing.Protocol

Jon

On Oct 26, 2022, at 06:45, TobiasHT <higenyi.tobias@gmail.com> wrote:

Is it possible to type an object that comprises of certain user defined methods?

I am writing a function that should accept a single argument which should be an instance of any object
that implements two methods, get and post. Is their a way of creating a type for it that can be scanned
by static type checkers?
_______________________________________________
Typing-sig mailing list -- typing-sig@python.org
To unsubscribe send an email to typing-sig-leave@python.org
https://mail.python.org/mailman3/lists/typing-sig.python.org/
Member address: jon@jonjanzen.com