Syntactic sugar for union cases in match statements

Ah, I see, you may need to make the tuple classes final to fix that. I forgot about it because pyright stopped needing final for TypedDicts when used in this manner, and that’s how I normally write it. (Commit where pyright changed this behaviour, which I always struggle to track down.)

class TagA(NamedTuple):
  a: TypeA

class TagB(NamedTuple):
  b: TypeB

TaggedUnion = TagA | TagB
1 Like