FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-141004: Document Py_ARRAY_LENGTH macro by Yashp002 · Pull Request #141601 · python/cpython · GitHub

/ cpython Public

gh-141004: Document Py_ARRAY_LENGTH macro - #141601

Merged
ZeroIntensity merged 12 commits into
python:mainfrom
Yashp002:main
Nov 24, 2025
Merged

gh-141004: Document Py_ARRAY_LENGTH macro#141601
ZeroIntensity merged 12 commits into
python:mainfrom
Yashp002:main

Conversation

Yashp002 commented Nov 15, 2025
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Contributor

This PR adds documentation for the Py_ARRAY_LENGTH macro to the C API documentation, addressing issue #141004.

The documentation is placed in the "Useful macros" section of Doc/c-api/intro.rst and includes:

  • A description of the macro's purpose (computing array length at compile time)
  • A warning that it must be used with C arrays, not pointers
  • An explanation that it's equivalent to sizeof(array) / sizeof((array)[0])

This macro has existed since Python 2.7 but was previously undocumented in the official C API documentation.


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

Added documentation for the Py_ARRAY_LENGTH macro, explaining its usage and requirements.
StanFromIreland changed the title Document Py_ARRAY_LENGTH macro in intro.rst gh-141004: Document Py_ARRAY_LENGTH macro in intro.rst Nov 15, 2025

Copy link
Copy Markdown
Member

Our CI does not like it when the branch the PR is opened from is called "main" IIRC and that is why some extra tests are running.

Comment thread Doc/c-api/intro.rst
Comment thread Doc/c-api/intro.rst Outdated
Yashp002 and others added 3 commits November 16, 2025 02:09
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>

Copy link
Copy Markdown
Contributor Author

Also, is it a generally good practice to break off a branch from the main while working on it myself then?

Comment thread Doc/c-api/intro.rst Outdated
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Comment thread Doc/c-api/intro.rst Outdated
compilation error, otherwise, using this macro with a pointer will
produce incorrect results.

This is generally equivalent to::

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I don't like the use of "generally" equivalent because it may indicate that it's equivalent to something else. So I would remove the "This is generally equivalent to:: + code"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I disagree, it's helpful to have something rather than nothing, even if it's not 100% true. This is a good example of a lie-to-children.

If you're against "generally", how about saying "this is semantically equivalent to ..."?

picnixz Nov 19, 2025
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

"generally" is inaccurate; if you want to lie a bit, you should say "roughly equivalent to" (which is what we do in academia or in itertools btw). "Generally" means that this would always be the case (at least to me when used like that), but the macro expansion is different.

  • If you want to use "generally" as a synonym of "usually", "roughly" is better.
  • "semantically equivalent" is too verbose IMO.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

"roughly equivalent to" is fine with me.

picnixz changed the title gh-141004: Document Py_ARRAY_LENGTH macro in intro.rst gh-141004: Document Py_ARRAY_LENGTH macro Nov 16, 2025
Removed redundant explanation of array size calculation.
Comment thread Doc/c-api/intro.rst Outdated
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>

ZeroIntensity left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Happy to see a new contributor :)

Comment thread Doc/c-api/intro.rst Outdated

.. c:macro:: Py_ARRAY_LENGTH(array)

Compute the length (number of elements) of a statically allocated C array at

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think it's generally well known that the length is the number of elements.

Comment thread Doc/c-api/intro.rst Outdated
Comment on lines +311 to +312
The *array* argument must be a C array with a size known at compile time,
not a pointer. On supported compilers, passing a pointer will result in a

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

All arrays can be represented as a pointer, statically allocated or not. Let's instead say something like "heap-allocated array" instead of "pointer".

Comment thread Doc/c-api/intro.rst Outdated
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>

Copy link
Copy Markdown
Contributor Author

Happy to see a new contributor :)

Thanks, I've been hoping to contribute to python since the longest time tbh 😄

Copy link
Copy Markdown
Member

Please address my comments and then I'll merge this.

Yashp002 and others added 3 commits November 20, 2025 23:50

ZeroIntensity left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM.

ZeroIntensity enabled auto-merge (squash) November 24, 2025 13:30
ZeroIntensity added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Nov 24, 2025

vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM

ZeroIntensity merged commit e0773ea into python:main Nov 24, 2025
36 checks passed
github-project-automation Bot moved this from Todo to Done in Docs PRs Nov 24, 2025

Copy link
Copy Markdown

Thanks @Yashp002 for the PR, and @ZeroIntensity for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 24, 2025
(cherry picked from commit e0773ea)

Co-authored-by: Yashraj <yashrajpala8@gmail.com>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>

bedevere-app Bot commented Nov 24, 2025

Copy link
Copy Markdown

GH-141895 is a backport of this pull request to the 3.14 branch.

bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Nov 24, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 24, 2025
(cherry picked from commit e0773ea)

Co-authored-by: Yashraj <yashrajpala8@gmail.com>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>

bedevere-app Bot commented Nov 24, 2025

Copy link
Copy Markdown

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

bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Nov 24, 2025

Copy link
Copy Markdown
Member

Congrats on your first contribution @Yashp002 :)

ZeroIntensity added a commit that referenced this pull request Nov 24, 2025
gh-141004: Document `Py_ARRAY_LENGTH` (GH-141601)
(cherry picked from commit e0773ea)

Co-authored-by: Yashraj <yashrajpala8@gmail.com>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
ZeroIntensity added a commit that referenced this pull request Nov 24, 2025
gh-141004: Document `Py_ARRAY_LENGTH` (GH-141601)
(cherry picked from commit e0773ea)

Co-authored-by: Yashraj <yashrajpala8@gmail.com>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
StanFromIreland added a commit to StanFromIreland/cpython that referenced this pull request Dec 6, 2025
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
ashm-dev pushed a commit to ashm-dev/cpython that referenced this pull request Dec 8, 2025
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir skip news

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants


Back | FazBrowse Home | New Git URL