Skip to content

Raise ValueError for a non-positive chunk_size#24

Open
santhreal wants to merge 1 commit into
isaacus-dev:mainfrom
santhreal:fix/validate-positive-chunk-size
Open

Raise ValueError for a non-positive chunk_size#24
santhreal wants to merge 1 commit into
isaacus-dev:mainfrom
santhreal:fix/validate-positive-chunk-size

Conversation

@santhreal

Copy link
Copy Markdown

Calling chunk (or a chunkerify-built chunker) with chunk_size of 0 or negative recurses until a RecursionError, since no chunk can ever hold a token and the split step never makes progress.

This validates chunk_size >= 1 on the first call and raises a clear ValueError instead.

import semchunk
semchunk.chunk("hello world", 0, len)  # was: RecursionError

A chunk_size of 0 or a negative value can never hold a single token, so
chunk() recursed until it hit RecursionError (reachable directly and via a
chunkerify-built chunker), e.g. from a caller that derives chunk_size
arithmetically. Validate chunk_size >= 1 on the first call and raise a clear
ValueError instead.
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.

1 participant