This comes from a mypy issue: https://github.com/python/mypy/issues/13191. Pyright does not handle this case correctly.