requests icon indicating copy to clipboard operation
requests copied to clipboard

Restore "packages" namespace for backwards compatibility

Open kennethreitz opened this issue 9 years ago • 21 comments

kennethreitz avatar May 27 '17 13:05 kennethreitz

shipped.

kennethreitz avatar May 27 '17 13:05 kennethreitz

I'm afraid this doesn't resolve the problem with many libraries, such as the official Dropbox and Keen clients, which do

from requests.packages.urllib3.poolmanager import PoolManager

This results in the following error:

ModuleNotFoundError: No module named 'requests.packages.urllib3'; 'requests.packages' is not a package

raicheff avatar May 27 '17 14:05 raicheff

I'm trying to find a solution for them too @raicheff. I'm open to suggestions.

Currently, code that was written to import against the requests.packages namespace previously will have to import code that rests at this module-level now.

For example:

from requests.packages.urllib3.poolmanager import PoolManager

Will need to be re-written to be:

from requests.packages import urllib3
urllib3.poolmanager.PoolManager

Or, even better:

from urllib3.poolmanager import PoolManager

kennethreitz avatar May 27 '17 14:05 kennethreitz

If we really want backwards compatibility, we may have to stub out the whole library as an empty imported package. I'm willing to do that, if needed.

kennethreitz avatar May 27 '17 14:05 kennethreitz

solution found!

kennethreitz avatar May 27 '17 14:05 kennethreitz

https://github.com/kennethreitz/requests/commit/c952e9e4e07ebaf579aaf8924ff6f7c61710c8c8

kennethreitz avatar May 27 '17 14:05 kennethreitz

@raicheff care to test against master and see if that solves the issue for you, for the next release?

kennethreitz avatar May 27 '17 14:05 kennethreitz

@kennethreitz Yes, just tested it and it works!

raicheff avatar May 27 '17 14:05 raicheff

\o/

kennethreitz avatar May 27 '17 14:05 kennethreitz

will cut a release shortly

kennethreitz avatar May 27 '17 14:05 kennethreitz

Thanks Kenneth, that's awesome!

This solution is ugly is hell, but I guess it will do the job for now. I would suggest you add a deprecation warning on import of these modules (similar to how Flask does it with the ext package), and remove the shimmed packages in the next major release.

raicheff avatar May 27 '17 14:05 raicheff

I came up with a much better solution.

kennethreitz avatar May 27 '17 14:05 kennethreitz

https://github.com/kennethreitz/requests/commit/28666e5d3ae04fede9a9078aba937b0ce6380adc

kennethreitz avatar May 27 '17 14:05 kennethreitz

going to cut a release

kennethreitz avatar May 27 '17 14:05 kennethreitz

shipped 2.16.2!

kennethreitz avatar May 27 '17 14:05 kennethreitz

Tested – works!

raicheff avatar May 27 '17 14:05 raicheff

With 2.16.2, coala's core tests are down to only one error, in an emulated read timeout test. https://circleci.com/gh/jayvdb/coala/296 We still have a few other issues which have strangely popped up, and probably some version conflicts for chardet. Still investigating.

jayvdb avatar May 27 '17 15:05 jayvdb

@jayvdb keep us up to date!

kennethreitz avatar May 27 '17 16:05 kennethreitz

@kennethreitz , I haven't found the cause of https://github.com/coala/coala/issues/4282 (and it is 3am so I'm off) , but the workaround was simple : https://github.com/coala/coala/pull/4283

jayvdb avatar May 27 '17 19:05 jayvdb

excellent @jayvdb!

kennethreitz avatar May 27 '17 19:05 kennethreitz