Skip to content
Preptima
mediumConceptCodingMidSenior

If you were writing a small value type in Python, which dunder methods would you implement, what would you let a dataclass generate, and how does super() decide what to call?

4 min readUpdated 2026-08-15

Answer

Short answer

Implement the dunders that opt your type into a protocol, treating repr, eq and hash as one decision, and let a dataclass generate the boilerplate when the fields are the identity.

Keep dunder methods explicit in the answer because that is the concept the interviewer is actually trying to test.

Was this answer helpful?

Likely follow-ups

  • Why does a frozen dataclass get a working __hash__ when a mutable one does not?
  • What does passing slots=True to dataclass change, and what does it break?
  • How would you validate field values on construction without writing __init__ by hand?
  • When is __init_subclass__ a better tool for enforcing a rule than a metaclass?

Related questions

Further reading

Related Topics