For context we found this from quora/pyanalyze#496, which makes pyanalyze stricter about context managers that may swallow exceptions. tempfile._TemporaryFileWrapper.__exit__ returns whatever its underlying file returns (https://github.com/python/cpython/blob/3.6/Lib/tempfile.py#L502), and file objects don't tend to return anything from __exit__.
* Make _TemporaryFileWrapper generic on AnyStr, use it
Previously it was not used on NamedTemoraryFile and thus the file
field was missing from the types for the return value of
NamedTemoraryFile.
If no arguments are passed to the TemporaryDirectory constructor, then
the class defaults to using str. Overload the __init__ function to
cover this case.
The TypeVar `_T` was being used as a type argument for `PathLike`, but `PathLike` requires that its type argument be constrained to `str` or `bytes`, and `_T` didn't provide any such constraint. The easy workaround is to use the TypeVar `AnyStr` instead.
Co-authored-by: Eric Traut <erictr@microsoft.com>