Avoid the chardet.universaldetector deprecation warning - #603
Open
afonsojanu wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #601.
chardet 7 moved
UniversalDetectortochardet.detectorand turned the oldchardet.universaldetectorimport into a stub that raises aDeprecationWarningthe 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
DeprecationWarningfrom the issue on unmodifiedmasterwith 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 anImportErroronchardet.detector. Ran the full test suite (git submodule update --initto 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.