Skip to content
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

Open
8 of 23 tasks
JukkaL opened this issue Jul 30, 2021 · 3 comments
Open
8 of 23 tasks

Primitives for common bytes operations #880

JukkaL opened this issue Jul 30, 2021 · 3 comments

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Jul 30, 2021

These operations related to bytes values are either common or "fundamental" and worth dedicated primitives if they help with performance:

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 to chr(x))
  • ord(b)
  • b * n

This is part of the wider issue #644.

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.
JukkaL pushed a commit to python/mypy that referenced this issue Aug 11, 2021
JukkaL pushed a commit to python/mypy that referenced this issue Aug 11, 2021
@ilevkivskyi
Copy link
Collaborator

Something that we discussed in the meeting that may be worth supporting (if there is time) is special-casing six.ensure_xxx() functions.

@SanjanaSogimatt
Copy link

Hey, I would like to work on this issue. I am new to open source so it would be great can contribute to it.

@TH3CHARLie
Copy link
Collaborator

@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
Projects
None yet
Development

No branches or pull requests

4 participants