Since typing doesn't yet have a way to express buffer protocol objects
(python/typing#593), various interfaces have ended up with a mish-mash
of options: some list just bytes (or just bytearray, when writable),
some include mmap, some include memoryview, I think none of them include
array.array even though it's explicitly mentioned as bytes-like, etc. I
ran into problems because RawIOBase.readinto didn't allow for
memoryview.
To allow for some uniformity until the fundamental issue is resolved,
I've introduced _typeshed.ReadableBuffer and _typeshed.WriteableBuffer,
and applied them in stdlib/3/io.pyi as an example. If these get rolled
out in more places, it will mean that we have only one place where they
have to get tweaked in future, or swapped out for a public protocol.
This unfortunately does have the potential to break code that inherits
from RawIOBase/BufferedIOBase and overrides these methods, because the
base method is now more general and so the override now needs to accept
these types as well (which is why I've also updated gzip and lzma).
However, it should be a reasonably easy fix, and will make the
downstream annotations more correct.
A few comments between imports were removed or moved to the top of the
import block, due to behavioral differences between black and isort. See
psf/black#251 for details.
In two instances @overloads at the top of the file needed to be moved
due to psf/black#1490.
write() is inherited from IO[bytes], where it's defined as
`def write(self, s: AnyStr) -> int: ...`. If AnyStr is bytes,
this should accept bytes, bytearray, and memoryview, so the
overload is unnecessary.
Closes: #4201
The return type of `__eq___` should be `bool`.
Otherwise, `mypy --disallow-any-unimported --no-silence-site-packages`
fails because the return type becomes `Union[bool, Any]` due to an
unfollowed import.
The CPython _lsprof module implementation uses the keyword arguments
'timer' and 'timeunit' instead of 'custom_timer' and 'time_unit' for
__init__. In profiler_init, the keyword argument parsing looks like the
following:
static char *kwlist[] = {"timer", "timeunit",
"subcalls", "builtins", 0};
This is the case ever since _lsprof was added in version 2.5.
Re-export the types from wsgiref.types for now to avoid breaking
existing code. wsgiref.types should be removed eventually.
Also, reduce the boilerplate description in _typeshed/wsgi.pyi as it
mirrors the description in _typeshed/__init__.pyi.
In Python 3.6, the SSLContext.options flags were converted from int to
EnumFlag values.
In addition, add the missing OP_ENABLE_MIDDLEBOX_COMPAT constant
introduced in version 3.6.
In addition, add the missing OP_NO_RENEGOTIATION constant introduced in
version 3.7.