Skip to content

gh-146086: Clarify sys.getsizeof() docstring regarding additional overhead#146087

Open
merkulovlad wants to merge 1 commit intopython:mainfrom
merkulovlad:fix-issue-146086
Open

gh-146086: Clarify sys.getsizeof() docstring regarding additional overhead#146087
merkulovlad wants to merge 1 commit intopython:mainfrom
merkulovlad:fix-issue-146086

Conversation

@merkulovlad
Copy link

@merkulovlad merkulovlad commented Mar 17, 2026

This change clarifies the short built-in documentation for sys.getsizeof().

The full documentation already explains that getsizeof() calls __sizeof__() and may add additional overhead (e.g., for the garbage collector). However, this distinction is not visible from the short help output (help() / pydoc).

This change adds a short clarification to reduce potential confusion.

This is a documentation-only change and does not affect runtime behavior. No NEWS entry is needed.

@python-cla-bot
Copy link

python-cla-bot bot commented Mar 17, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Mar 17, 2026

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@sergey-miryanov
Copy link
Contributor

I'm not sure it is worth doing. Added message doesn't no clarify the difference IMO, because there can be more extra data, that not calculated.

cc @picnixz

@merkulovlad
Copy link
Author

Thanks for the feedback!

I see your point that additional overhead is not limited to the garbage collector and that both __sizeof__() and sys.getsizeof() do not necessarily reflect the full memory usage.

My intention was mainly to reduce the potential confusion from the short help text, where __sizeof__() and sys.getsizeof() may appear equivalent.

Would it make sense either to:

  1. remove the specific reference to the garbage collector, or
  2. use a more general wording, for example:

The result may include additional memory overhead and may not reflect the total memory consumption of the object

Happy to adjust the wording based on your preference.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants