Skip to content

Avoid the chardet.universaldetector deprecation warning - #603

Open
afonsojanu wants to merge 1 commit into
html5lib:masterfrom
afonsojanu:fix/chardet-detector-deprecation-warning
Open

Avoid the chardet.universaldetector deprecation warning#603
afonsojanu wants to merge 1 commit into
html5lib:masterfrom
afonsojanu:fix/chardet-detector-deprecation-warning

Conversation

@afonsojanu

Copy link
Copy Markdown

Fixes #601.

chardet 7 moved UniversalDetector to chardet.detector and turned the old chardet.universaldetector import into a stub that raises a DeprecationWarning the moment it's imported. Anyone running their test suite with warnings turned into errors (like the reporter's Flexget project) hits a hard failure as soon as html5lib falls back to chardet for encoding detection.

The fix just tries the new import path first, falling back to the old one for older chardet installs, so both stay working without the warning firing on newer ones.

Reproduced the exact DeprecationWarning from the issue on unmodified master with a real chardet 7.6.0 install, confirmed it's gone with the fix, and confirmed the old-chardet fallback path still works by simulating an ImportError on chardet.detector. Ran the full test suite (git submodule update --init to pull in the testdata submodule first) - 19061 passed, 10873 skipped, 683 xfailed, one pre-existing unrelated failure (test_char_win1252, a chardet-version-dependent detection difference that fails identically on unmodified master). flake8 clean on the changed file.

Added a changelog entry and attributed myself in AUTHORS.rst per the contributing guide.

chardet 7 moved UniversalDetector to chardet.detector and turned the
old chardet.universaldetector import path into a stub that raises a
DeprecationWarning on import. Projects that run their test suites with
warnings turned into errors (like Flexget, per the linked issue) hit a
hard failure the moment html5lib falls back to chardet for encoding
detection.

Try the new import path first and fall back to the old one, so this
keeps working across both old and new chardet releases without
triggering the warning on the new ones. Fixes html5lib#601.
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.

DeprecationWarning: chardet.universaldetector is deprecated, import UniversalDetector from chardet or chardet.detector instead

1 participant