Skip to content

Modernize cChardet for Python 3.11–3.14 and stable 2.2.0 - #108

Merged
PyYoshi merged 12 commits into
masterfrom
chore/modernize-python-support
Sep 15, 2026
Merged

PyYoshi merged 12 commits into
masterfrom
chore/modernize-python-support

Conversation

@PyYoshi

@PyYoshi PyYoshi commented Sep 14, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • support CPython 3.11 through 3.14 and standardize local development, testing, and packaging on uv
  • update the bundled uchardet to the maintained PyYoshi fork without changing cChardet's expected API
  • release the GIL during native detection, avoid input copies, support bounded and streaming detection, and safely handle inputs beyond uchardet's internal 32-bit length
  • return encoding, confidence, and language results; expose ranked candidates with detect_all() and optional ISO 639-1 language downweights
  • add PEP 561 type information and bytes, bytearray, and memoryview support
  • add streaming, JSON, byte-limit, and language-weight options to cchardetect
  • publish reproducible performance and accuracy comparisons against optimized chardet and charset-normalizer, including their native accelerators and Pure Python fallbacks
  • strengthen native, arbitrary-byte, wheel, and release validation and document the external test-data and release policies

Benchmark highlights

CPython 3.14.2, AMD Ryzen 7 8845HS, identical preloaded 166-file / 641,202-byte corpus:

Detector Optimized serial Optimized 4-thread Pure fallback serial
cChardet 2.2.0a3 92.0 ms 42.1 ms n/a (native)
chardet 7.6.0 129 ms (mypyc) 209 ms 549 ms
charset-normalizer 3.5.1 88.7 ms (Cython) 110 ms 493 ms

Optimized charset-normalizer is competitive with cChardet for serial detection. cChardet retains a material advantage for concurrent independent buffers after releasing the GIL.

Accuracy on all 158 files in the bundled uchardet corpus:

Detector Encoding compatible Language Encoding + language
cChardet 94.30% 95.57% 91.14%
chardet 85.44% 87.34% 76.58%
charset-normalizer 72.15% 56.33% 45.57%

The analysis also reports exact and decode-equivalent results and keeps the independently maintained chardet and charset-normalizer corpora separate. See docs/performance-analysis.md for methodology, pinned revisions, limitations, and reproduction commands.

uchardet changes

  • use the maintained PyYoshi/uchardet cchardet branch rather than changing to an API-incompatible upstream revision
  • improve UTF-8 validation and GB18030 ranking
  • initialize multibyte prober state to remove a compiler warning found with warning-as-error builds
  • expose detector completion state through an additive C API
  • preserve the existing default ranking; language weights are strictly opt-in
  • pass all 153 enabled standalone uchardet C tests

Release preparation

  • prepare the unreleased stable 2.2.0 changelog while keeping the package version at 2.2.0a3 until the release commit
  • build wheels for CPython 3.11–3.14 on Linux, macOS, and Windows, including ARM64 targets
  • smoke-test installed wheels, including type-marker files and CLI behavior
  • build an sdist and publish tag builds through PyPI Trusted Publishing with attestations
  • document the required protected GitHub pypi environment and PyPI publisher setup
  • remove obsolete cibuildwheel.sh and manual GitHub release-asset download scripts

Verification

  • make check in the locked uv environment
  • ruff and strict mypy
  • 28 Python tests on CPython 3.11, 3.12, 3.13, and 3.14
  • 153/153 standalone uchardet C tests, including a warning-as-error build
  • wheel and sdist builds plus twine check
  • isolated installed-wheel smoke test
  • cibuildwheel build-identifier validation for the supported Linux targets
  • native ASan/UBSan job added to CI

Scope notes

  • free-threaded Python is intentionally not supported in this release
  • unlicensed external corpora and issue attachments are not downloaded or vendored; detector changes must be evaluated across complete, separately reported corpora

@PyYoshi
PyYoshi marked this pull request as draft September 14, 2026 16:31
@PyYoshi PyYoshi changed the title Modernize Python support and development tooling Modernize cChardet for Python 3.11–3.14 and stable 2.2.0 Sep 14, 2026
@PyYoshi
PyYoshi marked this pull request as ready for review September 15, 2026 00:07
@PyYoshi
PyYoshi merged commit cd49bc3 into master Sep 15, 2026
19 checks passed
@PyYoshi
PyYoshi deleted the chore/modernize-python-support branch September 15, 2026 00:08
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