ByteString, specifying length for any bytes-like variable
This request is a combination of two additions to ByteString that apparently are not supported yet, or at least I could find no discussion of them.
- Support any bytes-like buffers, not only
bytes,bytearrayandmemoryview - Allow specifying the length of the buffer expected (in my case it usually must be exactly 32 bytes)
Ideally, Python typing would allow specifying bytes-like of (a) any length, (b) fixed length or (c) min and/or max length. Potentially also separately specifying if a writable buffer is expected.
While I don't expect for mypy to be able to check for all of that, it would at least be nice to include such information in the annotations for documentation purposes, avoiding the use of docstrings for parameter definitions where names and types are descriptive enough. Is there any way to do this without causing mypy errors, considering that I would rather have no type checking but documentative annotations than what the current implementation can do?
Seems like a good use for PEP 593 Annotated.
Duplicate of #593.
@srittau Are you sure this issue is a duplicate of that one?
Support any bytes-like buffers, not only
bytes,bytearrayandmemoryviewAllow specifying the length of the buffer expected (in my case it usually must be exactly 32 bytes)
PEP 688 doesn't even contain the word “length”.
Thanks, I seem to have misunderstood the suggestion.