diff --git a/src/requests/__init__.py b/src/requests/__init__.py index ad842400b9..95a9b183d2 100644 --- a/src/requests/__init__.py +++ b/src/requests/__init__.py @@ -51,10 +51,11 @@ except ImportError: charset_normalizer_version = None -try: - from chardet import __version__ as chardet_version # type: ignore[import-not-found] -except ImportError: - chardet_version = None +# chardet is an optional dependency that should only be used if the +# use-chardet-on-py3 extra is installed. We no longer attempt to import it +# opportunistically, to avoid version warnings when chardet is installed +# by other packages without respecting requests' version constraints. +chardet_version = None def check_compatibility( diff --git a/src/requests/help.py b/src/requests/help.py index 9269cc7126..fdeba5f722 100644 --- a/src/requests/help.py +++ b/src/requests/help.py @@ -18,10 +18,10 @@ except ImportError: charset_normalizer = None -try: - import chardet # type: ignore[import-not-found] -except ImportError: - chardet = None +# chardet is an optional dependency that should only be used if the +# use-chardet-on-py3 extra is installed. We no longer attempt to import it +# opportunistically. +chardet = None try: from urllib3.contrib import pyopenssl