Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 25, 2025

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
Copy link
Contributor

coderabbitai bot commented Dec 25, 2025

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.

Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
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
Member

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

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