remove requests dependency#401
Conversation
… to get a correct type error
| return _client(kwargs).head(url, _stacklevel=4, **kwargs) | ||
|
|
||
|
|
||
| @_like(HTTPClient.get) |
There was a problem hiding this comment.
Interesting approach... I have a branch somewhere where I started factoring out TypedDict for all the arguments but it is so painful I haven't worked up the will to finish it.
There was a problem hiding this comment.
Oh, huh, will Mypy actually do the right thing with a TypedDict in this context?
There was a problem hiding this comment.
(I do think I prefer this approach regardless, that one had just never occurred to me.)
There was a problem hiding this comment.
I expect it will given Unpack (my experience actually doing this is with Pyright).
I certainly agree that this is less painful!
There was a problem hiding this comment.
It turns out that there are details that this can't capture (the addition of the agent= argument) so I ended up skipping it.
in the course of fixing a bunch of conflicts, also add a bunch of types
|
2 things in particular that I'd like feedback on from a reviewer, beyond the usual:
|
adiroiban
left a comment
There was a problem hiding this comment.
Is the goal of this PR to have a complete removal of requests ?
I guess that we should also update Python package definition and remove the requests dependency.
Line 40 in 724e458
Regarding typing. I think that it's a good improvement.
I don't have much feedback about typing as I am still not using Python typing on my day to day work... so I don't have much experience with that.
I don't think this needs more docs.
I think that the current docs page is good enough
https://treq.readthedocs.io/en/latest/#why
while on it, I have update the treq repo to link to the docs since I guess that this is the public website for the project
oh, yeah, this definitely needs to be done. |
aaaand done, in edd757f . I manually reviewed some |
adiroiban
left a comment
There was a problem hiding this comment.
It looks good.
Maybe we can have a CI task to check that 'requests' is not a dependency.
As a start. Something simple.
Maybe add this before installing tox.
treq/.github/workflows/ci.yaml
Lines 54 to 56 in 724e458
- name: Check that requests is not installed
run: |
python -m pip install .
if python -m pip freeze | grep -q "requests=="; then
echo "The 'requests' library should not be a dependency of the project"
false
fi
In this case a single manual test should work; we don't have ongoing regression tests to make sure we don't depend on NumPy or PyTorch for example :). The right way to do this is with constraints files, which we should eventually swtich to, but probably not as part of this change. |
twm
left a comment
There was a problem hiding this comment.
Thank you for taking this on, @glyph! I'm a bit too tired to fully review tonight, but I noted an issue with treq.request() that should really be addressed before merge.
One other thought — doesn't the requests cookie jar also support assignment indexing? IIRC, to create a ☢️ supercookie ☢️. There are some other extensions, like get() and set() take domain and path args, etc.
| :class:`hyperlink.EncodedURL` objects. | ||
| """ | ||
| return _client(kwargs).request(method, url, _stacklevel=3, **kwargs) | ||
| return _client(**kwargs).request(method, url, _stacklevel=3, **kwargs) |
There was a problem hiding this comment.
As _client() takes a different set of 4 arguments as .request() I don't think this'll work — it'll need the same re-declaration of all the arguments as get(), delete(), etc.
There was a problem hiding this comment.
Huh. How come the tests didn't catch this?
There was a problem hiding this comment.
It looks like there isn't any test that actually passes reactor. There's a similar issue if you pass agent, too.
|
|
||
| R = TypeVar("R") | ||
|
|
||
| SomeURL = Union[DecodedURL, EncodedURL, str, bytes] |
There was a problem hiding this comment.
Shouldn't this be _URLType? (Though SomeURL is a more pleasing name for it.)
There was a problem hiding this comment.
Maybe _SomeURL? Should it go in _types? I don't have strong feelings.
| allows for indexing to retrieve cookie values. This is for convenience and | ||
| for compatibility with `requests` users expectations. |
There was a problem hiding this comment.
I think that we should put a hazard warning sticker on this — it's dangerous to disregard the provenance of cookies in the face of HTTP redirects. IMO indexing by cookie name is dangerous enough that we should consider deprecating it, even as we do need it for compatibility. We provide the search() function as a safer interface.
|
|
||
| In general, you should not need to import or instantiate a | ||
| :py:class:`IndexableCookieJar` directly; anywhere that treq requires cookies, a | ||
| :py:class:`http.cookiejar.CookieJar` or ``dict`` of ``str`` to ``str`` |
There was a problem hiding this comment.
Perhaps use the typing syntax to be succinct?
| :py:class:`http.cookiejar.CookieJar` or ``dict`` of ``str`` to ``str`` | |
| :py:class:`http.cookiejar.CookieJar` or ``dict[str, str]`` |
| .. autoclass:: IndexableCookieJar | ||
|
|
There was a problem hiding this comment.
Since users aren't expected to instantiate this, should it live below scoped_cookie() and search() in the docs?
There was a problem hiding this comment.
No strong feelings from me on this one, but rearrange if you think it looks better.
|
Oh no. |
|
@twm Oops :). Do you think you could do a follow-up to address this stuff? I would rather intentionally leave off the supercookie-setitem; our own tests and examples don't depend on it. Should we deprecate the indexing support for similar reasons? |
|
@glyph I'm happy to follow up! I'd love to move this toward release. I think that while removing the remainder of the it is technically an incompatible change, most of the behavior I mentioned is so hazardous an interface that I'd rather not support it at all. I think that we can settle for acknowledging the compatibility implications in the changelog. |
Sounds good. I'll try to review when I can! |
Fixes #325
In order to know whether we are even testing the various requests extensions, we want to have type hints that actually reflect the signatures on all the helpers.
I've definitely bitten off more than I can chew for getting this done today, so if anyone else wants to have a look at this, please be my guest.