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

Assume there is no bytes/bytearray/memoryview implicit promotion #9001

Closed
JelleZijlstra opened this issue Oct 27, 2022 · 2 comments · Fixed by #9005
Closed

Assume there is no bytes/bytearray/memoryview implicit promotion #9001

JelleZijlstra opened this issue Oct 27, 2022 · 2 comments · Fixed by #9005
Labels
project: policy Organization of the typeshed project

Comments

@JelleZijlstra
Copy link
Member

JelleZijlstra commented Oct 27, 2022

Currently, we treat bytearray and memoryview as implicit subclasses of bytes, following the CPython documentation. In PEP 688, I propose to remove this implicit promotion. Discussion is still ongoing, but I'd like to make sure typeshed is ready for this change by reviewing existing usage of bytes.

To make that easier, I propose that we write stubs as if there is no implicit promotion between bytes, bytearray, and memoryview. Thus, if a function accepts either bytes or bytearray, we should write bytes | bytearray, not just bytes.

The only cost here should be that certain argument annotations become longer; everything should still work fine for type checkers that assume the implicit promotion.

If we agree on this rule, I can review existing bytes annotations for correctness. In my experience, most usages of bytes in argument positions should be ReadableBuffer.

@JelleZijlstra JelleZijlstra added the project: policy Organization of the typeshed project label Oct 27, 2022
@srittau
Copy link
Collaborator

srittau commented Oct 27, 2022

Sounds good, but this is quite a large task:

$ rgrep ": bytes" stubs/ stdlib/ | wc -l
1061

@JelleZijlstra
Copy link
Member Author

Hopefully most of them will be fairly easy. I'll update our docs to reflect this convention, then open a new issue with a TODO list for reviewing the stubs.

hauntsaninja added a commit to hauntsaninja/mypy that referenced this issue Oct 27, 2022
It might be useful to run mypy_primer without promotions in typeshed.
This would give us more confidence in changes stemming from
python/typeshed#9001
hauntsaninja added a commit to python/mypy that referenced this issue Oct 27, 2022
It might be useful to run mypy_primer without promotions in typeshed.
This would give us more confidence in changes stemming from
python/typeshed#9001
hauntsaninja added a commit to python/mypy that referenced this issue Oct 27, 2022
It might be useful to run mypy_primer without promotions in typeshed.
This would give us more confidence in changes stemming from
python/typeshed#9001
JelleZijlstra added a commit that referenced this issue Oct 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
project: policy Organization of the typeshed project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants