fix: Chardet is used, when it is available, not when `[use-charde#6
Open
echo-chamber0 wants to merge 1 commit into
Open
fix: Chardet is used, when it is available, not when `[use-charde#6echo-chamber0 wants to merge 1 commit into
echo-chamber0 wants to merge 1 commit into
Conversation
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.
Problem
When
chardetwas importable—because another package in the environment depended on it—src/requests/__init__.pyandsrc/requests/help.pywould attempt to import and use it unconditionally, even when the[use-chardet-on-py3]extra was not installed. This led to version-mismatch warnings when package managers installed a version ofchardetpinned by a third party that did not satisfy requests' optional-dependency constraints.Solution
The fix removes the opportunistic
chardetimport logic from both the main init and the help module. By no longer attempting to importchardetunless explicitly requested via the extra, requests respects the user's installation choice and avoids spurious warnings. This aligns the runtime behavior with the documented dependency model: optional dependencies should be opt-in, not used merely because they are present.src/requests/__init__.py— Removing the try-except import ofchardetensures requests does not use it unless theuse-chardet-on-py3extra is installed.src/requests/help.py— Removing the try-except import ofchardetprevents the help module from detecting and reporting a version that was never intended to be used.Verification
The post-patch validation run passed with 0 tests failed and the target test now passes. The baseline run before the patch exited with code 1, confirming the original issue was reproduced.
Closes psf#7223