TypedDict with extra items 0 ▲ mathspp.com feed 3 hours ago · Tech · hide · 0 comments Learn how to define a TypedDict that accepts extra items of a given type. A TypedDict is a type constructor that allows creating specialised types for dictionaries that have a fixed set of string keys: from typing import TypedDict class Movie(TypedDict): title: str year: int The snippet above creates a new type Movie that represents dictionaries with the key "title" and a string value, and the key "year" and an integer value: forrest_gump = {"title": "Forrest Gump", "year": 1994} In Python 3.15, TypedDict was improved to allow specifying whether or not the dictionary may have other keys and what must be the type of those other items when they're allowed. 15 days of Python 3.15 To celebrate the release of Python 3.15, over the next 15 business days I'll be writing about a new 3.15 feature every day. Explained clearly and with examples so you don't have to sift through the changelog. Subscribe to receive this free email series: Enroll for free 🐍🚀 If you want, you can also check the… No comments yet. Log in to reply on the Fediverse. Comments will appear here.