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

Support builtin str removeprefix/removesuffix #1033

Closed
wants to merge 2 commits into from

Conversation

jdimatteo
Copy link
Contributor

@google-cla google-cla bot added the cla: yes label Oct 18, 2021
@jdimatteo
Copy link
Contributor Author

jdimatteo commented Oct 19, 2021

removeprefix and removesuffix are also newly defined on bytes and bytearray in Python 3.9:

https://docs.python.org/3/library/stdtypes.html#bytes.removeprefix

The prefix may be any bytes-like object.

I didn't include these in this PR because I don't know how to represent "bytes-like object" as a type in pytype. It looks like in cpython the type corresponds to PyBytesObject. Would it be sufficient to just use typing.SupportsBytes? I unfortunately don't have a lot of bandwidth to track down these details.

Copy link
Contributor

@rchen152 rchen152 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the slow review! This looks good to me; I'll go ahead and import it once the tests finish running, assuming they don't find any unexpected issues.

@rchen152
Copy link
Contributor

re: bytes and bytearray - those are defined as their own classes in builtins.pytd, so you could add the new methods to them in the same way you did for str (just search for class bytes and class bytearray in https://github.com/google/pytype/blob/master/pytype/stubs/builtins/builtins.pytd).

@rchen152 rchen152 closed this in 1b5174b Oct 21, 2021
rchen152 added a commit that referenced this pull request Oct 28, 2021
This is a followup to #1033, which added
these methods for str. The bytes and bytearray methods accept any bytes-like
type, for which 'bytes' can be used as a shorthand
(https://docs.python.org/3/library/typing.html#typing.ByteString).

PiperOrigin-RevId: 405515077
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants