Skip to content

Align socket and socketserver with Python 3.15 final - #9156

Merged
youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:split/socket-315-final
Oct 16, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:split/socket-315-final

Conversation

@youknowdot

Copy link
Copy Markdown
Contributor

Summary

Split the socket/socketserver portion of #8954 into five files, synchronized with CPython 3.15 final (d220409a13b77de7a6c30abe16ea90db01528edc).

  • Import the complete socket.py, socketserver.py, test_socket.py, and test_socketserver.py using the actual scripts/update_lib copy/migrate commands. Preserve all five existing AF_ALG expected-failure markers. No hand-edited library/test bodies, duplicate snippets, support-module changes, or workflows.
  • Match setsockopt positional parsing, index-before-buffer conversion, and error ordering. Python conversions, warnings, and buffer acquisition finish before the socket lock; the socket guard drops before the buffer export is released.
  • Correct final-CPython optlen semantics beyond the original mega patch: use the index protocol, mask to unsigned 32 bits, and issue DeprecationWarning("integer value out of range") outside [-2**31, 2**32 - 1]. Warning-as-error propagates before the third-argument shape check or host call.
  • Reject Windows buffer lengths above INT_MAX before the host call.
  • Preserve arbitrary-precision integer ports in getaddrinfo, accept index objects before string/bytes handling, and return an empty canonical name when the resolver supplies none.

Provenance and overlap

The three Python files other than test_socket.py match the pinned CPython blobs byte-for-byte. test_socket.py differs only by the five retained AF_ALG decorators.

The tested commit is retained rather than rebased over unrelated main changes. At publication, the main-relative PR patch still contains exactly the reviewed five files. #9143 remains open and adds an expected-failure marker to test_getaddrinfo_int_port_overflow; that marker must be preserved if integrated because this run did not execute the real _testcapi-dependent body. The older socket overlap in #8007 concerns separate SSL/wait gating.

Local validation

Normal commit hooks, the matching narrow release build, and strict stdlib/VM all-targets Clippy passed:

cargo build --release --offline --locked -p rustpython --bin rustpython -j1 \
  --no-default-features --features threading,stdlib,stdio,importlib,host_env

cargo clippy --release --offline --locked -p rustpython-stdlib -p rustpython-vm \
  --all-targets --no-default-features \
  --features rustpython-stdlib/compiler,rustpython-stdlib/host_env,rustpython-stdlib/threading,rustpython-vm/compiler,rustpython-vm/gc,rustpython-vm/host_env,rustpython-vm/stdio,rustpython-vm/importlib,rustpython-vm/encodings,rustpython-vm/threading \
  -- -D warnings

Eight unchanged canonical method extracts passed, each in a fresh bounded process:

  • test_socket.GeneralModuleTests: testDefaultTimeout, testGetSockOpt, testSetSockOpt, test_setsockopt_errors, test_SocketType_is_socketobject, and testNewAttributes
  • test_socketserver.TestModule.test_deprecated__version__
  • test_socketserver.MiscTestCase.test_all

Four temporary supplemental checks passed: numeric-only getaddrinfo index/type/boundary/canonical-name cases; setsockopt optlen warnings and error order; a tiny native AF_UNIX socketpair/sendfile check; and socketserver attributes without starting a server. Every giant-optlen check supplied a non-None third argument and was rejected before host access. The sendfile fixture was 32 bytes, with 50 bytes transferred across the bounded cases; no external DNS was used.

The additional canonical test_getaddrinfo_int_port_overflow naturally skipped because the real _testcapi module is absent. Its body remains untested; no fake module or constants were substituted.

The runtime used the original library inventory with source/module-origin checks and time, memory, output, descriptor, and process limits. Initial missing native-math/IDNA admission failures were preserved, then corrected only in separately reviewed temporary import allowlists. No repository behavior or test assertion was changed to clear those gates. Source hashes remained unchanged across build, Clippy, and runtime, and an independent review checked the selected result receipts.

This is bounded Linux coverage, not a full test_socket/test_socketserver or workspace-suite pass. Windows/macOS/BSD/WASI behavior, broad DNS/non-UTF8/SSL/AF_VSOCK parity, raw-device tests, and server/fork loops were not exercised. The Windows length guard was source-reviewed only.

Validation identities:

  • Commit: ed08422bea7d1483a9a5a615870b7339a5dcc76b
  • Five-file patch SHA-256: e4493b63070d4578a60c1893273c5f791108a34d76781827730604d17b7c9624
  • Tested binary SHA-256: d44bdf898535141ef097c856552d332f1478443f69f14e515dc7307e1d288316
  • Result manifest SHA-256: 9f31d781770839feaebe550240542bf4ac7d5f4f3d7e09f54c58b6977e0bf36d

AI assistance

OpenAI Codex assisted with the implementation, canonical-source synchronization, source review, bounded validation, and this description. The exact model version was unavailable; the commit includes an Assisted-by trailer.

Import the canonical socket libraries and tests through update_lib, preserving the existing AF_ALG expected failures. Match setsockopt index/buffer conversion and error ordering, mask optlen with the final CPython deprecation warning, reject oversized Windows buffers before the host call, and preserve arbitrary-precision getaddrinfo ports and empty canonical names.

Assisted-by: OpenAI Codex:model version unavailable
@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: Repository: RustPython/RustPython/.coderabbit.yml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 880326b1-7b7b-4d2d-bd54-e111e2644dae
📥 Commits

Reviewing files that changed from the base of the PR and between 8e5709e and ed08422.

⛔ Files ignored due to path filters: 4
  • Lib/socket.py is excluded by !Lib/**
  • Lib/socketserver.py is excluded by !Lib/**
  • Lib/test/test_socket.py is excluded by !Lib/**
  • Lib/test/test_socketserver.py is excluded by !Lib/**
📒 Files selected for processing: 1
  • crates/stdlib/src/socket.rs
+-----------------------------------------------------------+
| This loop is doing cardio. Your users are doing timeouts. |
+-----------------------------------------------------------+
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

📦 Library Dependencies

The following Lib/ modules were modified. Here are their dependencies:

:4: SyntaxWarning: invalid decimal literal
:7: SyntaxWarning: "\z" is an invalid escape sequence. Such sequences will not work in the future. Did you mean "\z"? A raw string is also an option.
:10: SyntaxWarning: "\400" is an invalid octal escape sequence. Such sequences will not work in the future. Did you mean "\400"? A raw string is also an option.
:4: SyntaxWarning: invalid decimal literal
:7: SyntaxWarning: "\z" is an invalid escape sequence. Such sequences will not work in the future. Did you mean "\z"? A raw string is also an option.
:10: SyntaxWarning: "\400" is an invalid octal escape sequence. Such sequences will not work in the future. Did you mean "\400"? A raw string is also an option.
:4: SyntaxWarning: invalid decimal literal
:7: SyntaxWarning: "\z" is an invalid escape sequence. Such sequences will not work in the future. Did you mean "\z"? A raw string is also an option.
:10: SyntaxWarning: "\400" is an invalid octal escape sequence. Such sequences will not work in the future. Did you mean "\400"? A raw string is also an option.
[x] lib: cpython/Lib/socketserver.py
[x] test: cpython/Lib/test/test_socketserver.py

dependencies:

  • socketserver

dependent tests: (11 tests)

  • socketserver: test_imaplib test_logging test_socketserver test_wsgiref
    • http.server: test_httpservers test_robotparser test_urllib2_localnet test_xmlrpc
      • pydoc: test_enum test_pydoc
      • xmlrpc.server: test_docxmlrpc

[ ] lib: cpython/Lib/threading.py
[ ] lib: cpython/Lib/_threading_local.py
[ ] test: cpython/Lib/test/test_threading.py (TODO: 6)
[x] test: cpython/Lib/test/test_threadedtempfile.py
[x] test: cpython/Lib/test/test_threading_local.py

dependencies:

  • threading (native: _collections, _contextvars, _thread, itertools, sys, time)
    • _threading_local
    • _threading_local
    • collections (native: _collections, _weakref, itertools, sys)
    • contextlib (native: sys)
    • os (native: nt, os.path, posix, sys)
    • traceback (native: _missing_stdlib_info, _suggestions, collections.abc, importlib.machinery, importlib.resources.readers, importlib.util, itertools, sys, unicodedata)
    • weakref (native: _weakref, atexit, gc, itertools, sys)
    • _weakrefset, functools, warnings

dependent tests: (168 tests)

  • threading: test_android test_asyncio test_bytes test_bz2 test_code test_concurrent_futures test_context test_contextlib test_ctypes test_decimal test_docxmlrpc test_email test_enum test_enumerate test_external_inspection test_fork1 test_frame test_ftplib test_functools test_gc test_hashlib test_httplib test_httpservers test_imaplib test_importlib test_inspect test_io test_ioctl test_itertools test_largefile test_linecache test_logging test_memoryview test_opcache test_pathlib test_poll test_poplib test_pyrepl test_queue test_robotparser test_sched test_signal test_smtplib test_socket test_socketserver test_sqlite3 test_ssl test_subprocess test_super test_sys test_syslog test_termios test_threadedtempfile test_threading test_threading_local test_time test_urllib2_localnet test_weakref test_winreg test_wsgiref test_xmlrpc test_zstd
    • asyncio: test_asyncio test_concurrent_futures test_os test_pdb test_unittest
    • bdb: test_bdb
    • concurrent: test_compileall test_concurrent_futures test_genericalias test_struct test_types test_wmi
    • dummy_threading: test_dummy_threading
    • http.cookiejar: test_http_cookiejar test_urllib2
      • urllib.request: test_pathlib test_pydoc test_sax test_site test_urllib test_urllib2net test_urllibnet
    • importlib.util: test_asdl_parser test_ctypes test_doctest test_importlib test_pkgutil test_py_compile test_reprlib test_runpy test_zipfile test_zipimport
      • pkgutil: test_pyrepl
      • py_compile: test_argparse test_cmd_line_script test_importlib test_modulefinder test_multiprocessing_main_handling
      • pyclbr: test_pyclbr
      • sysconfig: test_c_locale_coercion test_cmd_line test_dtrace test_embed test_launcher test_osx_env test_peg_generator test_posix test_pyexpat test_regrtest test_support test_sysconfig test_tools test_venv
      • zipfile: test_shutil test_zipapp test_zipfile test_zipfile64 test_zipimport_support
    • logging: test_unittest
      • hashlib: test_hmac test_tarfile test_unicodedata
    • multiprocessing: test_fcntl test_re
    • queue: test_dummy_thread
    • subprocess: test_atexit test_audit test_ctypes test_faulthandler test_file_eintr test_gzip test_json test_msvcrt test_ntpath test_platform test_plistlib test_pyrepl test_quopri test_repl test_script_helper test_select test_sys_settrace test_tempfile test_traceback test_unittest test_utf8_mode test_wait3 test_webbrowser test_xpickle
      • ctypes.util: test_ctypes
      • ensurepip: test_ensurepip
      • platform: test__locale test__osx_support test_baseexception test_builtin test_cmath test_math test_mimetypes test_strptime
    • sysconfig:
      • trace: test_trace
    • zipfile:
      • shutil: test_filecmp test_glob test_peepholer test_string_literals test_unicode_file test_zoneinfo

[x] lib: cpython/Lib/socket.py
[x] test: cpython/Lib/test/test_socket.py (TODO: 5)

dependencies:

  • socket

dependent tests: (103 tests)

  • socket: test_asyncio test_epoll test_exception_hierarchy test_external_inspection test_ftplib test_httplib test_httpservers test_imaplib test_kqueue test_largefile test_logging test_mailbox test_mmap test_os test_pathlib test_poplib test_pty test_selectors test_signal test_smtplib test_smtpnet test_socket test_socketserver test_ssl test_stat test_subprocess test_support test_sys test_timeout test_urllib test_urllib2 test_urllib2net test_urllib_response test_urllibnet test_xmlrpc
    • asyncio: test_asyncio test_concurrent_futures test_inspect test_pdb test_unittest
    • email.utils: test_email
      • http.server: test_robotparser test_urllib2_localnet
      • logging.handlers: test_concurrent_futures test_pkgutil
      • urllib.request: test_http_cookiejar test_pydoc test_sax test_site
    • http.client: test_docxmlrpc test_hashlib test_ucn test_unicodedata test_wsgiref
    • http.server:
      • pydoc: test_enum
    • mailbox: test_genericalias
    • multiprocessing: test_compileall test_concurrent_futures test_fcntl test_memoryview test_multiprocessing_main_handling test_re
      • concurrent.futures.process: test_concurrent_futures
    • platform: test__locale test__osx_support test_baseexception test_builtin test_cmath test_ctypes test_math test_mimetypes test_platform test_posix test_regrtest test_shutil test_strptime test_sysconfig test_time test_winreg
    • ssl: test_venv
    • urllib.request:
      • pathlib: test_ast test_dbm_sqlite3 test_ensurepip test_importlib test_json test_launcher test_netrc test_pathlib test_peg_generator test_pyrepl test_runpy test_tarfile test_tempfile test_tomllib test_tools test_traceback test_unparse test_winapi test_zipapp test_zipfile test_zoneinfo test_zstd
    • uuid:
      • wave: test_wave

[ ] test: cpython/Lib/test/test_bytes.py (TODO: 15)

dependencies:

dependent tests: (no tests depend on bytes)

[x] test: cpython/Lib/test/test_thread.py (TODO: 1)
[ ] test: cpython/Lib/test/test_thread_local_bytecode.py
[x] test: cpython/Lib/test/test_threadsignals.py

dependencies:

dependent tests: (14 tests)
- [ ] concurrent.futures: test_asyncio test_compileall test_concurrent_futures test_context test_genericalias test_inspect test_struct test_wmi
- [ ] asyncio: test_asyncio test_external_inspection test_logging test_os test_pdb test_unittest

Legend:

  • [+] path exists in CPython
  • [x] up-to-date, [ ] outdated

@youknowone
youknowone marked this pull request as ready for review October 16, 2026 01:14
@youknowone
youknowone merged commit fd5b30e into RustPython:main Oct 16, 2026
31 checks passed
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-16T01:21:17.467424Z ed08422 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ed08422bea

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread Lib/test/test_socket.py
Comment on lines +1354 to +1355
with socket_setdefaulttimeout(10.125):
self.assertEqual(socket.getdefaulttimeout(), 10.125)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep the timeout test body unchanged

Do not land this imported test-body change: it changes timeout test data and assertions, while the repository policy permits test-file edits only for adding or removing expected-failure decorators. Keep this test body unchanged and validate the new behavior without modifying Lib/test.

AGENTS.md reference: AGENTS.md:L278-L282

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants