Skip to content

Fix object.__init__ excess-arg checks for heap types#7116

Open
moreal wants to merge 1 commit intoRustPython:mainfrom
moreal:object-init
Open

Fix object.__init__ excess-arg checks for heap types#7116
moreal wants to merge 1 commit intoRustPython:mainfrom
moreal:object-init

Conversation

@moreal
Copy link
Contributor

@moreal moreal commented Feb 13, 2026

Summary by CodeRabbit

  • Refactor
    • Internal improvements to how object type initialization is evaluated. No user-visible changes or behavioral impact.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 13, 2026

📝 Walkthrough

Walkthrough

Modified the type constructor argument validation in object.rs to replace direct slot-based comparison of __new__ methods with dynamic attribute retrieval and function identity checking. The code now uses get_attr() to retrieve __new__ attributes and is() to compare function identity, while maintaining equivalent error-handling behavior for __init__ argument validation.

Changes

Cohort / File(s) Summary
Constructor Argument Validation
crates/vm/src/builtins/object.rs
Replaced slot-based comparison of __new__ method addresses with dynamic attribute-based retrieval using get_attr() and identity comparison via is(). Control flow now depends on attribute lookup and function identity rather than raw slot addresses.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • Type alias type #6011: Modifies the same file's constructor argument-check logic by changing how type __new__/__init__ comparison is performed against object.__new__/object.__init__.

Poem

🐰 A hop from slots to attributes bright,
Dynamic checks dance into the night,
Identity verified with is() so true,
Where functions find themselves, both old and new! 🌙

🚥 Pre-merge checks | ✅ 2 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Merge Conflict Detection ⚠️ Warning ⚠️ Unable to check for merge conflicts: Failed to fetch base branch: From https://github.com/RustPython/RustPython
! [rejected] main -> main (non-fast-forward)
+ f960a0f...dd422a8 main -> origin/main (forced update)
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing object.__init__ excess-arg checks for heap types, which aligns with the technical change replacing slot-based comparison with dynamic attribute-based checking.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
⚔️ Resolve merge conflicts (beta)
  • Auto-commit resolved conflicts to branch object-init
  • Post resolved changes as copyable diffs in a comment

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
crates/vm/src/builtins/object.rs (1)

130-151: Inconsistent check strategy: __init__ still uses slot pointers while __new__ was switched to attribute identity.

In slot_init, lines 130–131 compare __init__ via slot function-pointer addresses, but lines 143–145 now compare __new__ via get_attr + is(). The slot_new function (lines 38–39, 53–54) uses the attribute-based approach for both __init__ and __new__ checks. This inconsistency suggests that if the slot-pointer approach is unreliable for heap types (which is why __new__ was switched to attribute checks in slot_init), the same issue likely applies to the __init__ check, and aligning both checks to use attribute identity would improve consistency across the codebase.


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 and usage tips.

@moreal moreal self-assigned this Feb 13, 2026
@github-actions
Copy link
Contributor

Code has been automatically formatted

The code in this PR has been formatted using:

  • cargo fmt --all
    Please pull the latest changes before pushing again:
git pull origin object-init

@moreal moreal force-pushed the object-init branch 3 times, most recently from 17ab286 to e4b0daf Compare February 14, 2026 03:18
@github-actions
Copy link
Contributor

📦 Library Dependencies

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

[ ] lib: cpython/Lib/fnmatch.py
[ ] test: cpython/Lib/test/test_fnmatch.py

dependencies:

  • fnmatch (native: itertools)
    • posixpath (native: errno, sys)
    • functools, os, re

dependent tests: (72 tests)

  • fnmatch: test_fnmatch test_os
    • bdb: test_bdb
    • glob: test_bz2 test_glob test_mailbox test_regrtest test_site test_zipimport
      • pathlib._abc: test_pathlib
    • shutil: test_argparse test_compileall test_ctypes test_filecmp test_httpservers test_importlib test_inspect test_largefile test_logging test_pkgutil test_py_compile test_reprlib test_shutil test_string_literals test_subprocess test_support test_sysconfig test_tempfile test_traceback test_venv test_zoneinfo
      • ctypes.util: test_ctypes
      • ensurepip: test_ensurepip
      • http.server: test_robotparser test_urllib2_localnet
      • tarfile: test_tarfile
      • tempfile: test_ast test_asyncio test_bytes test_cmd_line test_compile test_contextlib test_csv test_dis test_doctest test_faulthandler test_fileinput test_genericalias test_importlib test_linecache test_ntpath test_pathlib test_pickle test_pkg test_posix test_pydoc test_runpy test_selectors test_socket test_tabnanny test_termios test_threadedtempfile test_tomllib test_urllib test_urllib2 test_urllib_response test_zipapp test_zipfile test_zipfile64 test_zstd
      • webbrowser: test_webbrowser
      • zipfile: test_zipfile

[ ] lib: cpython/Lib/glob.py
[ ] test: cpython/Lib/test/test_glob.py

dependencies:

  • glob (native: itertools, sys)
    • stat
    • fnmatch
    • contextlib, functools, operator, os, re

dependent tests: (7 tests)

  • glob: test_bz2 test_glob test_mailbox test_regrtest test_site test_zipimport
    • pathlib._abc: test_pathlib

[ ] lib: cpython/Lib/pathlib
[ ] test: cpython/Lib/test/test_pathlib (TODO: 2)

dependencies:

  • pathlib (native: errno, itertools, pathlib._os, sys)
    • glob, posixpath, stat
    • _collections_abc, abc, io, ntpath, operator, os, typing

dependent tests: (68 tests)

  • pathlib: test_ast test_dbm_sqlite3 test_ensurepip test_httpservers test_importlib test_logging test_pathlib test_pkgutil test_runpy test_shutil test_tarfile test_tempfile test_tomllib test_tools test_traceback test_unparse test_venv test_winapi test_zipapp test_zipfile test_zoneinfo test_zstd
    • compileall: test_compileall
    • importlib: test_bdb test_cmd_line_script test_codecs test_ctypes test_doctest test_frozen test_hashlib test_importlib test_inspect test_linecache test_multiprocessing_main_handling test_py_compile test_pydoc test_reprlib test_sundry test_support test_unittest test_zipfile test_zipimport
      • inspect: test_abc test_argparse test_asyncgen test_builtin test_code test_collections test_coroutines test_decimal test_enum test_functools test_generators test_grammar test_ntpath test_operator test_patma test_posixpath test_signal test_type_annotations test_types test_typing test_unittest test_yield_from
      • py_compile: test_importlib
      • pyclbr: test_pyclbr
      • zipfile: test_zipfile test_zipfile64

[ ] lib: cpython/Lib/posixpath.py
[x] test: cpython/Lib/test/test_posixpath.py (TODO: 4)

dependencies:

  • posixpath

dependent tests: (40 tests)

  • posixpath: test_pathlib test_posixpath test_zipfile
    • fnmatch: test_fnmatch test_os
      • bdb: test_bdb
      • glob: test_bz2 test_glob test_mailbox test_regrtest test_site test_zipimport
      • shutil: test_argparse test_compileall test_ctypes test_filecmp test_httpservers test_importlib test_inspect test_largefile test_logging test_pkgutil test_py_compile test_reprlib test_shutil test_string_literals test_subprocess test_support test_sysconfig test_tempfile test_traceback test_venv test_zoneinfo
    • http.server: test_robotparser test_urllib2_localnet
      • wsgiref.simple_server: test_wsgiref
      • xmlrpc.server: test_docxmlrpc test_xmlrpc
    • importlib.metadata: test_importlib
    • zipfile._path: test_zipfile

[ ] lib: cpython/Lib/stat.py
[ ] test: cpython/Lib/test/test_stat.py

dependencies:

  • stat

dependent tests: (81 tests)

  • stat: test__osx_support test_argparse test_asyncio test_dbm_dumb test_dbm_sqlite3 test_http_cookiejar test_importlib test_inspect test_largefile test_mailbox test_os test_pathlib test_posix test_py_compile test_shutil test_site test_support test_tempfile test_zipapp test_zipfile
    • filecmp: test_compileall test_filecmp test_genericalias
    • genericpath: test_genericpath
      • ntpath: test_httpservers test_ntpath
      • posixpath: test_posixpath test_zipfile
    • glob: test_bz2 test_glob test_regrtest test_zipimport
    • posixpath:
      • fnmatch: test_fnmatch
      • http.server: test_logging test_robotparser test_urllib2_localnet
      • importlib.metadata: test_importlib test_zoneinfo
      • wsgiref.util: test_wsgiref
    • shutil: test_ctypes test_importlib test_pkgutil test_reprlib test_string_literals test_subprocess test_sysconfig test_traceback test_venv
      • ctypes.util: test_ctypes
      • ensurepip: test_ensurepip
      • tarfile: test_tarfile
      • tempfile: test_ast test_asyncio test_bytes test_cmd_line test_compile test_contextlib test_csv test_dis test_doctest test_faulthandler test_fileinput test_importlib test_linecache test_pickle test_pkg test_pydoc test_runpy test_selectors test_socket test_tabnanny test_termios test_threadedtempfile test_tomllib test_urllib test_urllib2 test_urllib_response test_zipfile64 test_zstd
      • webbrowser: test_webbrowser
    • zipfile: test_zipfile

[x] lib: cpython/Lib/abc.py
[x] lib: cpython/Lib/_py_abc.py
[ ] test: cpython/Lib/test/test_abc.py (TODO: 1)

dependencies:

  • abc

dependent tests: (8 tests)

  • abc: test_abc test_abstract_numbers test_binop test_copy test_dynamicclassattribute test_functools test_io test_typing

[ ] test: cpython/Lib/test/test_bool.py

dependencies:

dependent tests: (no tests depend on bool)

[ ] test: cpython/Lib/test/test_buffer.py

dependencies:

dependent tests: (no tests depend on buffer)

[ ] test: cpython/Lib/test/test_class.py (TODO: 15)
[x] test: cpython/Lib/test/test_genericclass.py
[x] test: cpython/Lib/test/test_subclassinit.py

dependencies:

dependent tests: (no tests depend on class)

[ ] lib: cpython/Lib/concurrent
[ ] test: cpython/Lib/test/test_concurrent_futures (TODO: 18)
[ ] test: cpython/Lib/test/test_interpreters
[ ] test: cpython/Lib/test/test__interpreters.py
[ ] test: cpython/Lib/test/test__interpchannels.py
[ ] test: cpython/Lib/test/test_crossinterp.py

dependencies:

  • concurrent (native: _interpqueues, _interpreters, concurrent.futures, concurrent.futures._base, itertools, multiprocessing.connection, multiprocessing.queues, sys, time)
    • collections (native: _weakref, itertools, sys)
    • logging (native: atexit, errno, logging.handlers, sys, time)
    • multiprocessing (native: _multiprocessing, _winapi, array, atexit, collections.abc, errno, itertools, mmap, msvcrt, sys, time)
    • pickle (native: itertools, sys)
    • types
    • functools, os, queue, threading, traceback, weakref

dependent tests: (11 tests)

  • concurrent: test_asyncio test_concurrent_futures test_context test_genericalias
    • asyncio: test_asyncio test_contextlib_async test_inspect test_logging test_os test_sys_settrace test_unittest

[ ] test: cpython/Lib/test/test_descr.py (TODO: 48)
[ ] test: cpython/Lib/test/test_descrtut.py (TODO: 1)

dependencies:

dependent tests: (no tests depend on descr)

[x] test: cpython/Lib/test/test_dict.py (TODO: 6)
[ ] test: cpython/Lib/test/test_dictcomps.py (TODO: 1)
[x] test: cpython/Lib/test/test_dictviews.py (TODO: 2)
[ ] test: cpython/Lib/test/test_userdict.py

dependencies:

dependent tests: (no tests depend on dict)

[x] test: cpython/Lib/test/test_float.py (TODO: 8)
[ ] test: cpython/Lib/test/test_strtod.py (TODO: 6)

dependencies:

dependent tests: (no tests depend on float)

[x] test: cpython/Lib/test/test_flufl.py (TODO: 4)

dependencies:

dependent tests: (no tests depend on flufl)

[x] lib: cpython/Lib/operator.py
[ ] test: cpython/Lib/test/test_operator.py (TODO: 3)

dependencies:

  • operator

dependent tests: (33 tests)

  • operator: test_abstract_numbers test_argparse test_array test_bigaddrspace test_bigmem test_binop test_builtin test_bytes test_collections test_complex test_copy test_ctypes test_dbm_dumb test_decimal test_enumerate test_float test_fractions test_heapq test_index test_ipaddress test_iterlen test_itertools test_numeric_tower test_plistlib test_richcmp test_set test_slice test_str test_struct test_sys test_typing test_weakref test_xml_etree

[ ] test: cpython/Lib/test/test_print.py (TODO: 7)

dependencies:

dependent tests: (no tests depend on print)

[ ] test: cpython/Lib/test/test_time.py (TODO: 24)
[ ] test: cpython/Lib/test/test_strftime.py

dependencies:

dependent tests: (134 tests)

  • time: test_android test_asyncio test_calendar test_compileall test_concurrent_futures test_context test_dummy_thread test_dummy_threading test_email test_epoll test_file_eintr test_float test_fork1 test_ftplib test_functools test_http_cookiejar test_httpservers test_imaplib test_importlib test_inspect test_io test_kqueue test_logging test_mailbox test_multiprocessing_main_handling test_os test_plistlib test_poll test_posix test_pydoc test_queue test_random test_resource test_sched test_selectors test_signal test_smtplib test_socket test_ssl test_strftime test_structseq test_subprocess test_sys test_syslog test_thread test_threading test_threadsignals test_time test_timeout test_urllibnet test_weakref test_xmlrpc test_zipfile test_zipfile64 test_zipimport
    • email.generator: test_email
      • mailbox: test_genericalias
      • smtplib: test_smtpnet
    • email.utils:
      • http.server: test_robotparser test_urllib2_localnet
    • http.server:
      • wsgiref.simple_server: test_wsgiref
      • xmlrpc.server: test_docxmlrpc
    • multiprocessing: test_concurrent_futures test_fcntl
    • pydoc: test_enum
    • queue: test_asyncio
    • socketserver: test_socketserver
    • subprocess: test_audit test_bz2 test_c_locale_coercion test_cmd_line test_cmd_line_script test_ctypes test_dtrace test_faulthandler test_gzip test_json test_msvcrt test_ntpath test_osx_env test_platform test_py_compile test_regrtest test_repl test_runpy test_script_helper test_select test_shutil test_site test_sqlite3 test_support test_sysconfig test_tempfile test_unittest test_urllib2 test_utf8_mode test_venv test_wait3 test_webbrowser
      • ctypes.util: test_ctypes
      • ensurepip: test_ensurepip
    • tarfile: test_tarfile
    • threading: test_asyncio test_code test_concurrent_futures test_contextlib test_decimal test_hashlib test_httplib test_importlib test_itertools test_largefile test_linecache test_opcache test_pathlib test_super test_termios test_threadedtempfile test_threading_local test_winreg test_zstd
      • sysconfig: test_pyexpat test_tools test_urllib2net
      • trace: test_trace
      • zipfile: test_pkgutil test_zipapp test_zipfile
    • timeit: test_timeit
    • urllib.request: test_pathlib test_urllib
    • zipfile:
      • importlib.metadata: test_importlib test_zoneinfo
    • zipimport: test_importlib

[x] lib: cpython/Lib/typing.py
[ ] test: cpython/Lib/test/test_typing.py (TODO: 5)
[x] test: cpython/Lib/test/test_type_aliases.py
[x] test: cpython/Lib/test/test_type_annotations.py (TODO: 1)
[x] test: cpython/Lib/test/test_type_params.py (TODO: 10)
[x] test: cpython/Lib/test/test_genericalias.py

dependencies:

  • typing

dependent tests: (14 tests)

  • typing: test_annotationlib test_builtin test_enum test_fractions test_funcattrs test_functools test_genericalias test_grammar test_isinstance test_pydoc test_type_aliases test_type_params test_types test_typing

Legend:

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

@moreal moreal marked this pull request as ready for review February 14, 2026 04:46
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.

1 participant