Skip to content

fix: Chardet is used, when it is available, not when `[use-charde#6

Open
echo-chamber0 wants to merge 1 commit into
mainfrom
df/7223/3T113614
Open

fix: Chardet is used, when it is available, not when `[use-charde#6
echo-chamber0 wants to merge 1 commit into
mainfrom
df/7223/3T113614

Conversation

@echo-chamber0
Copy link
Copy Markdown
Owner

Problem

When chardet was importable—because another package in the environment depended on it—src/requests/__init__.py and src/requests/help.py would 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 of chardet pinned by a third party that did not satisfy requests' optional-dependency constraints.

Solution

The fix removes the opportunistic chardet import logic from both the main init and the help module. By no longer attempting to import chardet unless 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 of chardet ensures requests does not use it unless the use-chardet-on-py3 extra is installed.

  • src/requests/help.py — Removing the try-except import of chardet prevents 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

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.

Chardet is used, when it is available, not when [use-chardet-on-py3]-extra is installed

1 participant