Skip to content
← All tracks

Structural Typing and the Hard Parts

Python

Protocols vs ABCs, overloads, `TypeIs`, `ParamSpec`, self types and the parts of the type system that fight back.

This track is written for Python, which isn't the mode you're browsing in.

0 / 19 solved · 5 articles
  1. 1. Not solved yet. Protocols: what structural subtyping actually asserts
  2. 2. Not solved yet. The protocol attribute invariance trap
  3. 3. Protocol or ABC: choosing the right kind of interface Read
  4. 4. Not solved yet. abc.ABC: abstract properties and classmethods, in the right order
  5. 5. Not solved yet. @runtime_checkable checks names, not types
  6. 6. Not solved yet. Subclassing a Protocol: what Python will and will not stop you doing
  7. 7. Not solved yet. Callback protocols: closing the Callable[..., Any] hole
  8. 8. Not solved yet. Variance in generic protocols
  9. 9. Disjoint bases (PEP 800): the types that cannot exist Read
  10. 10. Not solved yet. @overload: one implementation, several honest signatures
  11. 11. Not solved yet. ParamSpec and Concatenate: decorators that keep the signature
  12. 12. Not solved yet. TypeVarTuple: generics over an arbitrary number of types
  13. 13. Not solved yet. TypedDict: Required, NotRequired and the ReadOnly unlock
  14. 14. Closed TypedDicts and typed extra items (PEP 728) Read
  15. 15. Not solved yet. Unpack[TypedDict]: typing **kwargs precisely
  16. 16. Not solved yet. Annotated: metadata the type checker deliberately ignores
  17. 17. Not solved yet. Self-types, and restricting a method to one parameterisation
  18. 18. TypeForm: typing the values that are themselves types Read
  19. 19. Not solved yet. Auditing the Any surface of a module
  20. 20. Not solved yet. Replacing cast() with a TypeIs predicate
  21. 21. Not solved yet. Suppression hygiene: planning the minimum set of type: ignore
  22. 22. Not solved yet. __all__, re-export rules, and the accidental public API
  23. 23. py.typed and PEP 561: how a checker finds your types Read
  24. 24. Not solved yet. Writing a minimal .pyi for an untyped dependency

Check yourself

4 questions · one attempt each

These do not count toward finishing the track. They are here to catch the things that are easy to read past.

0 / 4

What does a TypedDict give you over a plain dict[str, object]?

class TD(TypedDict):
    name: str
    age: int

def use(t: TD) -> str:
    return t["nmae"]
Question 1 of 4