Ctrl K
Python · Mid-level · Theory

Your project just added mypy, and you need to type a function that accepts any object with a read method. Would you describe that type with a Protocol or with an abstract base class, and how do they differ?

~4 min by voice

How to approach it

This checks whether the candidate understands the difference between structural (Protocol) and nominal (ABC) typing in Python, what mypy checks and what the interpreter checks at runtime, and whether they can pick the right tool for the task "any object with a read method."

Have you seen this question in a real interview?
Answers0
Avg. score—
Strong—
Practiced0
Topics
Similar questionsWhy does Python need type annotations if it's a dynamic language? Are they checked when the program runs? JuniorWhen do you choose typing.Protocol and when an abstract base class? And how do you generally organize typing and mypy in a large project? Senior

Answer by voice

The interviewer will ask this question and listen. Think out loud and ask for a hint if you need one. When you're done, pause or tap “That's my answer”. In about a minute, your score and the points you covered show up here.

Sign in to answer

Best with headphones · ~4 min