It makes sense that variables in a NamedTuple and a frozen dataclass should be considered read-only and should therefore not cause a TypeVar to be inferred as invariant.
Interestingly, Python 3.13’s addition of a
__replace__method effectively breaks this.
Seems really related to what I was worried about in Proposal: Optional Explicit covariance/contravariance for PEP 695.
Maybe explicit is better than implicit after all.