New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[9643] Agent.request(method) must be bytes #1146
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for making Twisted web client more usable!
Approved, but consider the suggestion for improvement
src/twisted/web/client.py
Outdated
@@ -1714,6 +1714,9 @@ def request(self, method, uri, headers=None, bodyProducer=None): | |||
|
|||
@see: L{twisted.web.iweb.IAgent.request} | |||
""" | |||
if not isinstance(method, bytes): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to do it in _AgentBase._requestWithEndpoint
, so that ProxyAgent
won't have literally the same bug?
This is not a blocker, but should be considered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's not a blocker, a new ticket for that issue should at least be filed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not make it a blocker, and also fix the ProxyAgent ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point, probably because moshez already approved the PR and it is contributor unfriendly to have conflicting requirements imposed on their contributions. If there's an issue here, the reasonable next step is probably to discuss with moshez why he didn't think this should be a blocker and come to some agreement for future work.
FWIW, the PR as-is seems like a specific, concrete improvement to a feature of Twisted. It is not incomplete because it does not also address ProxyAgent
. It would be great to also fix ProxyAgent
but no harm is done by taking on that work separately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I agree.
just a comment... instead of raising an error, why not try to recover from the error and convert the method using 'ASCII' encoding? I expect that in most of the people are just calling it using something like |
Because this would introduce failures that depend on the value instead of on the type. Then, these failures would happen based on program input instead of program construction and be harder to predict, track down, and fix. |
Fair point... is harder to detect value based errors. My understanding is that HTTP method name is a "token" so is safe to assume that you will always receive ASCII characters.
I was hoping that in this way it will be bit easier to migrate to py3. |
That's always a nice thing to hope for but I think in reality it will make it harder to migrate to Python 3 and then also harder to maintain the resulting Python 3 code. |
It absolutely would make it easier to port code that uses Agent to Python 3 if this argument were
Actually value-dependent failures here are already possible because the implementation doesn't actually verify that I do think that checking the type is enough to avoid much user confusion. |
Thank you for the review, @moshez! I did as you suggested with |
You're welcome, and since it's already approved, you can merge at will :) |
Raise
TypeError
when themethod
argument ofAgent.request()
isn'tbytes
.It would be more usable to make it accept
str
as well, but that would require changes toIAgent.request()
which is explicit about it beingbytes
. Since third partyIAgent
implementations are actually a thing, I don't think that we should make that change.Contributor Checklist: