Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-129675: Update documentation for tp_basicsize & tp_itemsize #129850

Merged
merged 3 commits into from
Mar 11, 2025

Conversation

encukou
Copy link
Member

@encukou encukou commented Feb 8, 2025

  • Add alignment requirement
  • Mention that ob_size is unreliable if you don't control it
  • Add some links for context
  • basicsize should include the base type in generaly not just PyObject

This adds a “by-the-way” link to PyObject_New, which shouldn't be used for GC types. In order to be comfortable linking to it, I also add a link to PyObject_GC_New from its docs. And the same for *Var variants, while I'm here.


📚 Documentation preview 📚: https://cpython-previews--129850.org.readthedocs.build/

- Add alignment requirement
- Mention that ob_size is unreliable if you don't control it
- Add some links for context
- basicsize should include the base type in generaly not just PyObject

This adds a “by-the-way” link to `PyObject_New`, which shouldn't be
used for GC types. In order to be comfortable linking to it, I also
add a link to `PyObject_GC_New` from its docs. And the same for
`*Var` variants, while I'm here.
Comment on lines -603 to -604
exceptions: for example, ints use a negative :c:member:`~PyVarObject.ob_size` to indicate a
negative number, and N is ``abs(ob_size)`` there. Also, the presence of an
Copy link
Member Author

@encukou encukou Feb 17, 2025

Choose a reason for hiding this comment

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

@markshannon FWIW, here's another piece of documentation that says abs(ob_size) gives you the size of a PyLongObject.

Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

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

Mostly LGTM. Feel free to ignore any of my comments, these are pretty much just what I thought to myself as I read through it.

Copy link
Member Author

@encukou encukou left a comment

Choose a reason for hiding this comment

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

Thanks for the review!

Things can always be improved, but it looks like this iteration is good to go.

Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM :)

@encukou encukou merged commit ad0f618 into python:main Mar 11, 2025
24 checks passed
@encukou encukou added awaiting core review needs backport to 3.12 bug and security fixes needs backport to 3.13 bugs and security fixes labels Mar 11, 2025
@miss-islington-app
Copy link

Thanks @encukou for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Thanks @encukou for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 11, 2025
…ythonGH-129850)

* Update documentation for tp_basicsize & tp_itemsize

- Add alignment requirement
- Mention that ob_size is unreliable if you don't control it
- Add some links for context
- basicsize should include the base type in generaly not just PyObject

This adds a “by-the-way” link to `PyObject_New`, which shouldn't be
used for GC types. In order to be comfortable linking to it, I also
add a link to `PyObject_GC_New` from its docs. And the same for
`*Var` variants, while I'm here.

* Strongly suggest Py_SIZE & Py_SET_SIZE
(cherry picked from commit ad0f618)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
@bedevere-app
Copy link

bedevere-app bot commented Mar 11, 2025

GH-131078 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 bug and security fixes label Mar 11, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 11, 2025
…ythonGH-129850)

* Update documentation for tp_basicsize & tp_itemsize

- Add alignment requirement
- Mention that ob_size is unreliable if you don't control it
- Add some links for context
- basicsize should include the base type in generaly not just PyObject

This adds a “by-the-way” link to `PyObject_New`, which shouldn't be
used for GC types. In order to be comfortable linking to it, I also
add a link to `PyObject_GC_New` from its docs. And the same for
`*Var` variants, while I'm here.

* Strongly suggest Py_SIZE & Py_SET_SIZE
(cherry picked from commit ad0f618)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
@bedevere-app
Copy link

bedevere-app bot commented Mar 11, 2025

GH-131079 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Mar 11, 2025
encukou added a commit to rhansen/cpython that referenced this pull request Mar 11, 2025
encukou added a commit that referenced this pull request Mar 17, 2025
…GH-129850) (GH-131078)

- Add alignment requirement
- Mention that ob_size is unreliable if you don't control it
- Add some links for context
- basicsize should include the base type in generaly not just PyObject
- suggest Py_SIZE & Py_SET_SIZE

This adds a “by-the-way” link to `PyObject_New`, which shouldn't be
used for GC types. In order to be comfortable linking to it, I also
add a link to `PyObject_GC_New` from its docs. And the same for
`*Var` variants, while I'm here.

(cherry picked from commit ad0f618)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
encukou added a commit that referenced this pull request Mar 17, 2025
…GH-129850) (GH-131079)

- Add alignment requirement
- Mention that ob_size is unreliable if you don't control it
- Add some links for context
- basicsize should include the base type in generaly not just PyObject
- suggest Py_SIZE & Py_SET_SIZE

This adds a “by-the-way” link to `PyObject_New`, which shouldn't be
used for GC types. In order to be comfortable linking to it, I also
add a link to `PyObject_GC_New` from its docs. And the same for
`*Var` variants, while I'm here.

(cherry picked from commit ad0f618)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
@encukou encukou deleted the tp_xsize-docs branch March 17, 2025 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants