Skip to content
Myr

Only alias the imports for vendored dependencies

Before adoption: this commit came in with the history the project adopted, so no landing records it.

While discussion the issue, Donald Stufft (@dstufft) and I realized the simplest solution is to simply add an alias per vendored dependency. The resulting changes are simple and effective. It prevents the issue in 2.5.2 and 2.5.3 where the following would work: from requests.packages import webbrowser This now appropriately raises an ImportError. Closes #2465

authored by Ian Cordasco · committed by Ian Cordasco · parent 461b740 · Browse files · 1 file+4 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+4 added−3 removed

  • other:+4 added−3 removed

1 file+4 added−3 removed

modified:requests/packages/__init__.py+4 added-3 removed
25 unmodified lines
262728class VendorAlias(object):2930 def __init__(self):30 def __init__(self, package_name):31 self._package_name = package_name32 self._vendor_name = __name__32 self._vendor_pkg = self._vendor_name + "."33 self._vendor_pkg = self._vendor_name + "." + self._package_name3435 def find_module(self, fullname, path=None):36 if fullname.startswith(self._vendor_pkg):37 return self
54 unmodified lines
92 # Finally, return the loaded module93 return module949595sys.meta_path.append(VendorAlias())96sys.meta_path.extend([VendorAlias("urllib3"), VendorAlias("chardet")])