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

iterutils.chunked and chunked_iter raise TypeError for bytes objects #231

Closed
craigholm opened this issue Dec 30, 2019 · 1 comment
Closed

Comments

@craigholm
Copy link

>>> chunked('abc123', 3)
['abc', '123']
>>> chunked(b'abc123', 3)
Traceback (most recent call last):
  File "<pyshell#13>", line 1, in <module>
    chunked(b'abc123', 3)
  File "C:\Program Files\Python38\lib\site-packages\boltons\iterutils.py", line 197, in chunked
    return list(chunk_iter)
  File "C:\Program Files\Python38\lib\site-packages\boltons\iterutils.py", line 242, in chunked_iter
    yield postprocess(cur_chunk)
  File "C:\Program Files\Python38\lib\site-packages\boltons\iterutils.py", line 233, in <lambda>
    postprocess = lambda chk, _sep=type(src)(): _sep.join(chk)
TypeError: sequence item 0: expected a bytes-like object, int found
@mahmoud
Copy link
Owner

mahmoud commented Jan 7, 2020

Ah, shoot, this is because bytes objects in py3 turn into streams of integers when iterated on. But they stay bytes when sliced. I might need to put some special handling in here just for bytes to match expectations (and py2 behavior). Thanks for the heads up!

@mahmoud mahmoud closed this as completed in 9b3392a Jan 7, 2020
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

2 participants