Skip to content

Pass max_bytes parameter to UniversalDetector in detect() and detect_all()#314

Merged
dan-blanchard merged 1 commit intochardet:mainfrom
bysiber:fix/pass-max-bytes-to-detector
Feb 20, 2026
Merged

Pass max_bytes parameter to UniversalDetector in detect() and detect_all()#314
dan-blanchard merged 1 commit intochardet:mainfrom
bysiber:fix/pass-max-bytes-to-detector

Conversation

@bysiber
Copy link
Copy Markdown
Contributor

@bysiber bysiber commented Feb 20, 2026

detect() and detect_all() both accept a max_bytes parameter, but neither passes it to the UniversalDetector constructor. The detector always uses the default value of 200,000 regardless of what the caller specifies.

# Before: max_bytes is accepted but silently ignored
result = chardet.detect(large_data, max_bytes=1000)
# Still examines up to 200,000 bytes

# After: max_bytes is properly forwarded
result = chardet.detect(large_data, max_bytes=1000)
# Now actually limits examination to 1000 bytes

…all()

Both detect() and detect_all() accept a max_bytes parameter but never
pass it to the UniversalDetector constructor, so the detector always
uses the default of 200,000 regardless of what the caller specifies.

This passes max_bytes through so the parameter actually takes effect.
@dan-blanchard
Copy link
Copy Markdown
Member

Thanks for the fix!

@dan-blanchard dan-blanchard merged commit 7a59079 into chardet:main Feb 20, 2026
19 checks passed
dan-blanchard added a commit that referenced this pull request Mar 12, 2026
…arade history

- Add contributor names with GitHub profile links to all changelog entries
- Add PR/issue links where available across all versions
- Add missing entries: 6.0.0.post1, max_bytes fix (#314), Codespaces (#312),
  LGPLv2.1 update (#307), ISO-8859-15 (#222), LGPL classifier (#255),
  Hypothesis testing (#66), UTF-16/32 BOM fix (#73), early exit (#103)
- Include charade fork releases (1.0.0–1.0.3) interleaved chronologically
- Prefix pre-merger versions with "chardet" or "charade" for clarity
- Add sphinx-lint to prek pre-commit hooks

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

2 participants