Loading topic
Protocol, use it to annotate parameters, and6 min readProtocol, you know type hints, and you have run mypy or pyright at least once. Here you will learn the exact rules a checker applies when it compares a class to a protocol. That helps you predict errors and read their messages.4 min readProtocol and know that a type checker matches classes to it by shape. It covers the other option: naming the protocol in a class's bases. You will see what that changes at runtime and in the checker, when it helps, and where it goes wrong.6 min readProtocol. It also assumes you know that a static type checker such as mypy or pyright analyzes code without running it. Here you will see how a protocol can take part in isinstance checks 5 min readtyping.Protocol for methods. Here the same idea is applied to functions.4 min readProtocol, you know how type checkers such as mypy or pyright match a class to a protocol by shape, and you have seen TypeVar and list[int]-style generics. Here you combine the two ideas. You will make protocols generic, constrain type variables with a5 min readIterable[str] or Sized, you are using a protocol. This chapter shows which standard-library types are protocols, how your own classes qualify for them, and where the exceptions are.5 min read@runtime_checkable, and explicit subclassing.5 min readProtocol, know how a type checker such as mypy or pyright matches a class to it, and have seen @runtime_checkable. It covers how to size and shape protocols so they stay useful, and the mistakes that most often make them confusing or wrong.5 min read