Skip to content

Align object.__sizeof__ with CPython for ints#6516

Closed
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-sizeof-compatibility
Closed

Align object.__sizeof__ with CPython for ints#6516
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-sizeof-compatibility

Conversation

Copilot AI commented Dec 25, 2025

Copy link
Copy Markdown
Contributor

The base object.__sizeof__ returned only the type basic size, underreporting memory for variable-sized ints compared to CPython.

  • Int-aware sizing: object.__sizeof__ now calculates int sizes using the same bit-length-based formula as int.__sizeof__, ensuring parity for arbitrary-sized integers.
  • Regression guard: Added a snippet test to assert object.__sizeof__ is never smaller than int.__sizeof__ for a very large integer.

Example:

big = 10**200
assert object.__sizeof__(big) >= big.__sizeof__()  # matches CPython-style sizing
Original prompt

This section details on the original issue you should resolve

<issue_title>object.__sizeof__ is not compatible with CPython implementation</issue_title>
<issue_description>When you run the below code, you can see the difference. ⬇️

# RustPython
>>>>> object.__sizeof__(1223456789812391231291231231231212312312312312312312321321321321312312321123123123199129391239219394923912949213021949302194942130123949203912430392402139210492139123012940219394923942395943856228368385)
32

# CPython
>>> object.__sizeof__(1223456789812391231291231231231212312312312312312312321321321321312312321123123123199129391239219394923912949213021949302194942130123949203912430392402139210492139123012940219394923942395943856228368385)
116

Plan (tracking)

<agent_instructions>Investigate why the size is different and try to properly implement it</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@coderabbitai

coderabbitai Bot commented Dec 25, 2025

Copy link
Copy Markdown
Contributor

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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

Copilot AI changed the title [WIP] Fix object.__sizeof__ compatibility with CPython implementation Align object.__sizeof__ with CPython for ints Dec 25, 2025
Copilot AI requested a review from youknowone December 25, 2025 10:23
@youknowone

Copy link
Copy Markdown
Member

This is too ad-hoc. There must be the right way

Copilot AI and others added 3 commits January 15, 2026 08:49
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
@youknowone youknowone force-pushed the copilot/fix-sizeof-compatibility branch from 4c3e63c to 747b998 Compare January 15, 2026 00:06
@youknowone youknowone closed this Mar 7, 2026
@youknowone youknowone deleted the copilot/fix-sizeof-compatibility branch March 7, 2026 00:21
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.

object.__sizeof__ is not compatible with CPython implementation

2 participants