BUG: unclosed file warning when passing invalid encoding
This isn't directly related to #30031 but might solve it if the problem there is unclosed files piling up.

TL;DR: the actual problem is in the stdlib `codecs.open`:

```
def open(filename, mode='r', encoding=None, errors='strict', buffering=1):
    if encoding is not None and 'b' not in mode:
        mode = mode + 'b'
    file = builtins.open(filename, mode, buffering)
    if encoding is None:
        return file
    info = lookup(encoding)
    srw = StreamReaderWriter(file, info.streamreader, info.streamwriter, errors)
    # Add attributes to simplify introspection
    srw.encoding = encoding
    return srw
```

When we pass a bogus encoding "foo" in test_format, the `lookup` call raises, and leaves behind the file opened a few lines earlier.
Pretty interesting - is there something on bpo for this? should we consider replacing all uses of codecs. used in a few other places? seems the windows builds failed with this change for some reason. > is there something on bpo for this?

Just opened https://bugs.python.org/issue38971

> should we consider replacing all uses of codecs. used in a few other places?

Maybe?  I'd want to track down why we're using codecs.open in the first place (best guess is a py2/py3 compat legacy)

> seems the windows builds failed with this change for some reason.

Yah, looks like we're getting '\n' instead of '\r\n' somewhere along the way.  Shouldn't be too hard to troubleshoot.

 windows problem was fixed by passing `newline=""` thanks