I need to type-hint that a value is either some TypedDict or a completely empty dict. The TypedDict itself already exists and is non-trivial, and it's an all-or-nothing situation – so modifying the TypedDict to have optional keys is not sufficient.
Both of these are used in a context where its important whether I have one or the other (because they are handled differently) and in a context where any dict with the key-value types of the TypedDict is acceptable (e.g. serialising to JSON).
How can I type-hint the "completely empty dict" part?
The expectation is that this a) signals that no specific key can be read or written but b) still be read in any place an arbitrary-size Mapping of specific key-value types is expected.
Since I already use TypedDict, defining an empty TypedDict seems natural. However, neither MyPy nor PyRight meaningfully accept this: the resulting type cannot actually be used even as a trivial Mapping.
from typing import TypedDict, Mapping
class EmptyDict(TypedDict): pass
def foo(bar: Mapping[str, float]) -> None:...
foo(EmptyDict())
error: Argument 1 to "foo" has incompatible type "EmptyDict"; expected "Mapping[str, float]" [arg-type]
Argument of type "EmptyDict" cannot be assigned to parameter "bar" of type "Mapping[str, float]" in function "foo" "EmptyDict" is not assignable to "Mapping[str, float]" Type parameter "_VT_co@Mapping" is covariant, but "object" is not a subtype of "float" "object" is not assignable to "float" (reportArgumentType)
Mapping[str, float](which implies a float value for any string key, whereas an empty dictionary is a key error for every key)?TypedDictthat does not haveextra_items=orclosed=set is considered to have an item with a value of typeReadOnly[object]"