gh-107545: Fix misleading setsockopt error message#107546
gh-107545: Fix misleading setsockopt error message#107546serhiy-storchaka merged 11 commits intopython:mainfrom
Conversation
|
Most changes to Python require a NEWS entry. Please add it using the blurb_it web app or the blurb command-line tool. |
|
I choose to solve the issue using a white-list approach rather then a black-list approach since there might be more errors that Error message for: import socket
with socket.socket() as s:
s.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 2 ** 31)is now |
|
Looks good, how about adding some tests for new error messages. |
|
I added the relevant tests. Any new review comments? |
Considering this is your first PR in cpython, please be patient! The next step is waiting for the review by core devs. Generally, core developers don't have enough time to review every PR, so you can see there are many PRs that can't be merged into the main. Before they come to review, we just need to keep our PR compliant and wait :) |
f712b65 to
6439014
Compare
6439014 to
167d212
Compare
|
Since this PR is old, I validated that the issue is still reproducible. |
serhiy-storchaka
left a comment
There was a problem hiding this comment.
LGTM, but I think that we can get rid of _testcapi.
The more user friendly approach is to parse arguments as "iiOO|O" and then use == Py_None, PyIndex_Check() and PyBuffer_Check() for the third argument. This will allow to generate better error messages like "... should be integer, bytes-like object or None".
|
Thanks for the feedback. |
|
Thank you for your update, @naweiss. Here is the next portion of comments. |
I noticed this too. We need to look at the history of the code. Anyway, this is a different issue. |
vstinner
left a comment
There was a problem hiding this comment.
LGTM.
@serhiy-storchaka: Would you mind to review the latest version of this change?
…e-107545.ipfl7U.rst Co-authored-by: Victor Stinner <vstinner@python.org>
|
Thank you for your PR, @naweiss. After merging it, would you mind to create an issue and a PR for unification for |
|
Thanks @naweiss for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14. |
|
GH-137411 is a backport of this pull request to the 3.14 branch. |
No problem. Does it really make sense to have all overloads for AF_VSOCK? |
|
In general, And I think that it will make the code simpler. |
|
Congrats @naweiss for your change! |
According to Python's documentation,
setsockoptcan get eitherint,bufferorNoneas the third argument.The way it is currently implemented is by trying to parse all of the three arguments as ints, if this fails no matter what the reason is we just try the next overload.
Since
2**31causesPyExc_OverflowErrorwe try the next overloads. Because thebufferoverload is last we get type error for the third argument instead ofOverflowError(e.g.TypeError: a bytes-like object is required, not 'int').setsockopterror message #107545