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

Adjust for removal of typing.ByteString in Python 3.14 #639

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

michel-slm
Copy link

typing.ByteString has been removed:

https://docs.python.org/3.14/whatsnew/3.14.html

The modernizing guide suggests collections.abc.ByteString which has also been removed; the recommendation is to use either:

  • just bytes
  • collections.abc.Buffer
  • a union of bytes, bytesarray, etc.

https://typing.readthedocs.io/en/latest/guides/modernizing.html#modernizing-byte-string

https://docs.python.org/3/library/collections.abc.html#collections.abc.ByteString suggests bytes | bytesarray so I'm going with that here.

@lyterk
Copy link
Contributor

lyterk commented Feb 10, 2025

I think it's fine to just use bytes, it looks like the only caller using ByteString is struct.unpact, handling user input here. struct.unpack consumes bytes | bytesarray | memoryview. When handling user input from a string, only the bytes type make sense.

So we could easily just get rid of the ByteString type and use bytes with no loss of specificity or type safety.

@kellyjonbrazil
Copy link
Owner

kellyjonbrazil commented Feb 10, 2025

So we could easily just get rid of the ByteString type and use bytes with no loss of specificity or type safety.

This is probably the way to go since the bytes | bytesarray syntax may not work for older Python versions, which we need to support:

https://github.com/kellyjonbrazil/jc/actions/runs/13249946013/job/36985283625?pr=639

@kellyjonbrazil kellyjonbrazil changed the base branch from master to dev February 10, 2025 20:35
@michel-slm
Copy link
Author

I'll rework - should I start from the dev branch to make the PR cleaner?

`typing.ByteString` has been removed:

https://docs.python.org/3.14/whatsnew/3.14.html

The modernizing guide suggests `collections.abc.ByteString` which has
also been removed; the recommendation is to use either:

- just `bytes`
- `collections.abc.Buffer`
- a union of `bytes`, `bytesarray`, etc.

https://typing.readthedocs.io/en/latest/guides/modernizing.html#modernizing-byte-string

Per discussion, using `bytes` should suffice

Signed-off-by: Michel Lind <[email protected]>
@kellyjonbrazil
Copy link
Owner

Looks good - I'll merge when I start working on the next release. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants