Continuing work towards #8988.
The first five commits were created using stubdefaulter on various Python versions; the following commits were all created manually by me to fix various problems. The main things this adds that weren't present in #9501 are:
- Defaults in Windows-only modules and Windows-only branches (because I'm running a Windows machine)
- Defaults in non-py311 branches
- Defaults for float parameters
- Defaults for overloads
The name `_DirT` implies that it is a `TypeVar`, but it isn't; it's a generic `TypeAlias` that can be parameterised with a `TypeVar`. Rename it to just `_Dir` instead.
Also, use aliases instead of repeating incredibly long Literal annotations six times.
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>