New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Primitives for common bytes operations #880
Labels
Comments
JukkaL
pushed a commit
to python/mypy
that referenced
this issue
Aug 4, 2021
Use `PyBytes_FromObject` for `bytes(o)`. Use `PyByteArray_FromObject` for `bytearray(o)`. Current approach doesn't support empty initialization. Related to mypyc/mypyc#880.
JukkaL
pushed a commit
to python/mypy
that referenced
this issue
Aug 5, 2021
Similar to list and tuple, we can directly get length of bytes from PyVarObject->ob_size. Implements part of mypyc/mypyc#880.
This was referenced Aug 9, 2021
JukkaL
pushed a commit
to python/mypy
that referenced
this issue
Aug 11, 2021
Implements part of mypyc/mypyc#880.
JukkaL
pushed a commit
to python/mypy
that referenced
this issue
Aug 11, 2021
Implements part of mypyc/mypyc#880.
Something that we discussed in the meeting that may be worth supporting (if there is time) is special-casing |
Hey, I would like to work on this issue. I am new to open source so it would be great can contribute to it. |
@SanjanaSogimatt feel free to pick one that has been implemented yet. You can use @97littleleaf11 PRs as examples. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
These operations related to
bytes
values are either common or "fundamental" and worth dedicated primitives if they help with performance:len(b)
b[n]
(indexing)==
,!=
([mypyc] Implement bytes equality optimizations python/mypy#10928)<
,<=
, etc.b[:n]
etc. (slicing) ([mypyc] Add primitive for bytes slicing python/mypy#10966)s.encode(<literal>)
(forutf8
,ascii
andlatin1
)s.encode(x)
(for an arbitrary encoding)b.decode(<literal>)
(forutf8
,ascii
andlatin1
)b.decode(x)
(for an arbitrary encoding)%
formattingb.join(...)
b.split(...)
These operations in
six
are also quite common in many codebases:ensure_str
ensure_binary
These are somewhat common and fairly easy to implement:
b.startswith(...)
b.endswith(...)
b.lower()
b.upper()
b.strip()
Maybe also support these (fundamental but not very common operations):
bytes([n])
(corresponds tochr(x)
)ord(b)
b * n
This is part of the wider issue #644.
The text was updated successfully, but these errors were encountered: