Fix `'WriteToConn' object has no attribute 'flush'` (#16801)
`WriteToConn` replaces stdout and stderr to capture output, but causes
issues because it doesn't implement the `TextIO` API (as expected of
`sys.stdout` and `sys.stderr`).
By stubbing the rest of the `TextIO` API we prevent issues with other
code which uses more of the API than we had previously accounted for.
Fixes https://github.com/python/mypy/issues/16678