-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
gh-107545: Fix misleading setsockopt error message #107546
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
base: main
Are you sure you want to change the base?
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. |
Misc/NEWS.d/next/Core and Builtins/2023-08-01-22-30-35.gh-issue-107545.f9i3pQ.rst
Outdated
Show resolved
Hide resolved
Co-authored-by: Charlie Zhao <zhaoyu_hit@qq.com>
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 :) |
According to Python's documentation,
setsockopt
can get eitherint
,buffer
orNone
as the first arguments.The way it is implemented currently is:
cpython/Modules/socketmodule.c
Lines 3169 to 3190 in f01e4ce
So, we first try to parse all of the three arguments as ints, if this fails no matter what the reason is we just try the next overload. So since
2**31
causesPyExc_OverflowError
exception, and thebuffer
overload is last you get type error for the third argument instead (e.g.TypeError: a bytes-like object is required, not 'int'
).setsockopt
error message #107545