Skip to content

Missing bytearray.copy in Python 3 #1715

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

Closed
futursolo opened this issue Nov 6, 2017 · 6 comments
Closed

Missing bytearray.copy in Python 3 #1715

futursolo opened this issue Nov 6, 2017 · 6 comments

Comments

@futursolo
Copy link

The superclass MutableSequence of builtin object bytearray is not properly typed in the current stub file(stdlib/3/typing.pyi), which is missing method clear.

@linw1995
Copy link

and this,
error: "bytearray" has no attribute "copy"

@ExplodingCabbage
Copy link
Contributor

Looks like this was resolved by #1765

Possible @linw1995's issue is not resolved, though?

Probably makes sense to close this and then open a separate issue for sorting out copy.

@JelleZijlstra
Copy link
Member

Making changes to typeshed is easy. Could you just submit a PR adding a copy method to bytearray?

@ExplodingCabbage
Copy link
Contributor

@JelleZijlstra I didn't really understand the rationale for not putting it on MutableSequence given that the docs state that all MutableSequences should have .copy(). I assume this doesn't just affect bytearray, but I'm not sure. I don't feel comfortable that I know what the right resolution is here, but I figure that probably it involves fixing the documentation/implementation inconsistency in collections.abc's MutableSequence, rather than hacking around it on typeshed.

@JelleZijlstra
Copy link
Member

There does seem to be a discrepancy between the docs and the implementation, in that the MutableSequence ABC in the stdlib does not define a copy() method. Two solutions:

  • Report a bug to CPython about the discrepancy, which would presumably be resolved either by changing the docs or by adding .copy() to the MutableSequence ABC (most likely only in 3.7). Then we could add .copy() to MutableSequence in typeshed, though again probably only for 3.7.
  • Add the .copy() method to the stub for bytearray in typeshed. (list, the other prominent MutableSequence, has it already.)

@ExplodingCabbage
Copy link
Contributor

Hmm, I see your rationale. Since even if the issue gets fixed in Python 3.7 we'd want to add .copy() to bytearray anyway to support Python <=3.7, it makes sense to add it now.

Cool, if I get a chance I'll take a look at making that PR - unless somebody else beats me to it.

JelleZijlstra added a commit to JelleZijlstra/typeshed that referenced this issue May 15, 2018
Fixes python#1715.

2.7's bytearray doesn't have it.
@JelleZijlstra JelleZijlstra changed the title error: "bytearray" has no attribute "clear". Missing bytearray.copy in Python 3 May 15, 2018
gvanrossum pushed a commit that referenced this issue May 15, 2018
Fixes #1715.

2.7's bytearray doesn't have it.
gwk pushed a commit to gwk/typeshed that referenced this issue May 29, 2018
Fixes python#1715.

2.7's bytearray doesn't have it.
yedpodtrzitko pushed a commit to yedpodtrzitko/typeshed that referenced this issue Jan 23, 2019
Fixes python#1715.

2.7's bytearray doesn't have it.
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

No branches or pull requests

4 participants