You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ByteString, specifying length for any bytes-like variable #997
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, bytearray and memoryview
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?
Activity
hauntsaninja commentedon Dec 31, 2021
Seems like a good use for PEP 593 Annotated.
srittau commentedon Jan 2, 2022
Duplicate of #593.
James-E-A commentedon Feb 11, 2025
@srittau Are you sure this issue is a duplicate of that one?
PEP 688 doesn't even contain the word “length”.
srittau commentedon Feb 12, 2025
Thanks, I seem to have misunderstood the suggestion.