Simplify Traversable.open() signature. This is necessary so that implentors can
reasonanbly implement this method. For example `zipfile.Path.open()` (which
is considered a `Traversable`) only supports this subset.
Make `Traversable.__truediv__` and `joinpath` arguments pos-only. The
arguments are named differently in both `pathlib.Path` and `zipfile.Path`.
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
* Replace `Str[OrBytes]Path` with `str`
A filesystem path is not valid as an abstract resource.
`TraversableResources` cannot only accept strings if `ResourceReader`
accepts both bytes and strings. `importlib.resources` does not work
with bytes in any case and `ResourceReader` is typed as taking
a `typing.Text` object in `importlib.resources`' source code.
* Update `joinpath` signature from Python 3.11
As pointed out by @gvanrossum in https://github.com/python/typing/issues/1096
Improves type inference in cases when we know that mode is
OpenBinaryMode, but don't know anything more specific:
```
def my_open(name: str, write: bool):
mode: Literal['rb', 'wb'] = 'wb' if write else 'rb'
with open(name, mode) as f:
reveal_type(f) # previously typing.IO[Any], now typing.BinaryIO
```
You may be tempted into thinking this is some limitation of type
checkers. mypy does in fact have logic for detecting if we match
multiple overloads and union-ing up the return types of matched
overloads. The problem is the last overload interferes with this logic.
That is, if you remove the fallback overload (prior to this PR), you'd get
"Union[io.BufferedReader, io.BufferedWriter]" in the above example.
Co-authored-by: hauntsaninja <>