We can't find the internet
Attempting to reconnect
Something went wrong!
Attempting to reconnect
Interfaces with Protocols and ABCs
PythonDescribe what a function needs from its arguments with protocols and abstract base classes. Then give precise types to dictionaries, overloads and decorators, and find where Any and missing stubs leave code unchecked.
This track uses Python. You can make it your practice mode to browse related content across the site.
Your learning sequence
- 1 Accept Any Object That Has the Right Methods Read
- 2 Not solved yet. Write a Protocol for Three Unrelated Classes Practice · Easy
- 3 Choose Between a Protocol and an ABC Read
- 4 Not solved yet. Build an ABC with an Abstract Property and Classmethod Practice · Easy
- 5 Not solved yet. Catch the Backends That isinstance Lets Through Practice · Medium
- 6 Not solved yet. Inherit a Default Method from a Protocol Practice · Medium
- 7 Not solved yet. Type a Handler Registry with a Callback Protocol Practice · Medium
- 8 Not solved yet. Fix the Variance of a Serializer and a Parser Practice · Hard
- 9 Not solved yet. Make a Protocol Member Read-Only with a Property Practice · Hard
- 10 Not solved yet. Describe a Dictionary's Keys with TypedDict Practice · Easy
- 11 Not solved yet. Accept Three Event Types with a Read-Only TypedDict Practice · Medium
- 12 Not solved yet. Type **kwargs with a TypedDict and Unpack Practice · Medium
- 13 Not solved yet. Type a Lookup with a Default Using Overloads Practice · Hard
- 14 Not solved yet. Write Decorators That Keep the Signature with ParamSpec Practice · Hard
- 15 Not solved yet. Check Number Ranges at Runtime with Annotated Practice · Medium
- 16 Not solved yet. Restrict One Method to String Builders with Self Types Practice · Medium
- 17 Not solved yet. Find Where Any Leaks into Function Signatures Practice · Medium
- 18 Not solved yet. Validate Records with TypeIs Instead of cast Practice · Medium
- 19 Not solved yet. Clean Up type: ignore Comments Practice · Easy
- 20 Not solved yet. Work Out What __all__ and Re-exports Make Public Practice · Medium
- 21 Ship Your Library's Type Hints with py.typed Read
- 22 Not solved yet. Write a Minimal Stub for an Untyped Package Practice · Hard
- 23 Not solved yet. Keep the Type at Each Tuple Position with TypeVarTuple Practice · Hard
- 24 Control the Extra Keys of a TypedDict Read
- 25 Accept Types Like str | None as Arguments with TypeForm Read
- 26 Why Some Classes Cannot Share a Subclass Read
Check yourself
5 questions · not saved while you're signed outUse these questions to check your understanding and compare explanations. Your score does not affect track completion.
What does NotRequired[str] allow for the email key?
Choose one answer to reveal the explanations. Answers are kept only while this page is open.
from typing import NotRequired, TypedDict
class User(TypedDict):
name: str
email: NotRequired[str]
ada: User = {"name": "Ada"}