What is Protocol and when is it useful?
Answer
•Protocol describes a "duck type" by methods.
•Allows typing interfaces without inheritance.
•Example: an object with a .read() method.
•Useful for mocks and abstractions.
•Requires typing.Protocol (3.8+) or typing_extensions.
Was this answer helpful?