On 4/19/22 11:24 AM, Steven Troxler wrote:
For what it's worth, at runtime it will work fine to do this with: ``` def transpose(p: P) -> P: return { **p, "x": p['y'], "y": p['x'], } ```
Thanks Steven! This is a much better solution to the "copy on write" use case. Succinct and works today. I wasn't aware you could put individual keys after a ** splat in a dictionary literal.
MyPy complains about this but Pyre and Pyright both accept it.
Hmm, true (for the MyPy case). I don't think MyPy understands splats (**) inside dict literals that are intended to be used as a TypedDict. I expect it would take only a moderate amount of effort to add support if this notation became popular to use. Cheers, -- David Foster | Seattle, WA, USA Contributor to TypedDict, mypy, and Python's typing system