From 1278ecdf71a312dc2268f3bfc0aabfab3c006dcf Mon Sep 17 00:00:00 2001 From: Ryan Pineo Date: Mon, 29 May 2017 17:25:56 -0400 Subject: [PATCH] Fix requests.packages not having package attributes Fixes #4104 --- AUTHORS.rst | 1 + requests/packages.py | 2 +- tests/test_packages.py | 13 +++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 tests/test_packages.py diff --git a/AUTHORS.rst b/AUTHORS.rst index 121c725b..7e0bddf0 100755 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -182,3 +182,4 @@ Patches and Suggestions - David Fontenot (`@davidfontenot `_) - Shmuel Amar (`@shmuelamar `_) - Gary Wu (`@garywu `_) +- Ryan Pineo (`@ryanpineo `_) diff --git a/requests/packages.py b/requests/packages.py index 1fc3a742..7232fe0f 100644 --- a/requests/packages.py +++ b/requests/packages.py @@ -4,7 +4,7 @@ import sys # I don't like it either. Just look the other way. :) for package in ('urllib3', 'idna', 'chardet'): - __import__(package) + locals()[package] = __import__(package) # This traversal is apparently necessary such that the identities are # preserved (requests.packages.urllib3.* is urllib3.*) for mod in list(sys.modules): diff --git a/tests/test_packages.py b/tests/test_packages.py new file mode 100644 index 00000000..b55cb68c --- /dev/null +++ b/tests/test_packages.py @@ -0,0 +1,13 @@ +import requests + + +def test_can_access_urllib3_attribute(): + requests.packages.urllib3 + + +def test_can_access_idna_attribute(): + requests.packages.idna + + +def test_can_access_chardet_attribute(): + requests.packages.chardet