
El sáb, 4 mar 2023 a las 11:44, Eric Traut (<eric@traut.com>) escribió:
I'll note that the dictionary syntax for a TypedDict definition would work only within type annotations, not within other locations where types are used. In those locations, it would be evaluated as a regular dictionary object, not a type definition. For example, you wouldn't be able to use this in a call to `cast`, `isinstance`, as a base class for a class declaration, as bounds for a `TypeVar`, within a traditional (pre-PEP 695) type alias definition, etc.
As I understand the proposal, no new syntax is being proposed: we would merely allow additional syntax in types that is currently rejected by type checkers, though it is already allowed at runtime. Therefore, many of the contexts you cite could be made to work without language-level changes. For example, `cast({"a": int, "b": str}, {})` is legal syntax today, and under the proposal we're discussing it would have a sensible meaning. The exceptions are `isinstance()` and base classes. However, `isinstance()` already does not work with TypedDicts. Inheriting from an anonymous TypedDict is a potentially meaningful operation, but it's unlikely to be useful, since inheriting from a TypedDict can only give you another TypedDict.