TYP: Update mypy and pyright
The first commit contains changes for only the mypy update.

The second commit contains only changes for pyright 1.1.399 (this commit has three remaining errors caused by a bug fixed in 1.1.400 ).

The third commit tries to get to 1.1.400. One major change in 1.1.400 is that pyright now also infers missing return annotations for partially annotated functions. Many of these functions would require complex overloads or ignore codes. I added a few overloads but for now, I would prefer to update to 1.1.399 (and ignore the error fixed in 1.1.400).
Thanks @twoertwein 