Skip to content

gh-149402: don't assume single-character type codes (struct/array/ctypes)#149483

Merged
vstinner merged 6 commits into
python:mainfrom
skirpichev:improve-pep3118-docs-p1/149402
May 11, 2026
Merged

gh-149402: don't assume single-character type codes (struct/array/ctypes)#149483
vstinner merged 6 commits into
python:mainfrom
skirpichev:improve-pep3118-docs-p1/149402

Conversation

@skirpichev
Copy link
Copy Markdown
Member

@skirpichev skirpichev commented May 7, 2026

In the struct docs, section "Format Characters" was renamed to "Type Codes".

…ay/ctypes)

In the struct docs, section "Format Characters" was renamed to "Type
Codes".
@skirpichev skirpichev requested a review from vstinner May 7, 2026 04:56
@bedevere-app bedevere-app Bot added docs Documentation in the Doc dir skip news awaiting review labels May 7, 2026
@github-project-automation github-project-automation Bot moved this to Todo in Docs PRs May 7, 2026
@skirpichev
Copy link
Copy Markdown
Member Author

RTFD failure seems to be not related to the PR.

@vstinner
Copy link
Copy Markdown
Member

vstinner commented May 7, 2026

"docs/readthedocs.org:cpython-previews" failed with:

Error while cloning the repository: There was a problem cloning your repository. Please check the command output for more information.

Too bad, I like to use it to read rendered documentation :-)

@skirpichev
Copy link
Copy Markdown
Member Author

Maybe you can restart it?

@vstinner
Copy link
Copy Markdown
Member

vstinner commented May 7, 2026

In the struct docs, section "Format Characters" was renamed to "Type Codes".

Hum. I wanted to proposing renaming them to "Format Strings", but a "Format String" has already a different meaning in struct, it's the whole string starting with an optional endian character (@, <, >, =, !), followed by format characters with size and alignment. Format Strings: https://docs.python.org/dev/library/struct.html#format-strings.

The term "type code" is already used by the array module: the "type codes" table has a "type column", and there is the array.typecodes tuple. It's good to reuse the term. Doc: https://docs.python.org/dev/library/array.html

memoryview.cast() first parameter is called "format", and it's a format string (format character with an optional "@" prefix). Doc: https://docs.python.org/dev/library/stdtypes.html#memoryview.cast. cast() error message says "native format".

I think that I'm fine with replacing "Format Characters" with "Type Codes" :-)

Can you replace "format characters" with "type codes" in Objects/memoryview.c in comments and in the error:

        PyErr_SetString(PyExc_ValueError,
            "memoryview: destination format must be a native single "
            "character format prefixed with an optional '@'");

@vstinner
Copy link
Copy Markdown
Member

vstinner commented May 7, 2026

Maybe you can restart it?

I don't see how I can restart a failed RTD job. But it's fine, it will be retried at the next commit anyway.

@skirpichev
Copy link
Copy Markdown
Member Author

Can you replace "format characters" with "type codes" in Objects/memoryview.c in comments and in the error:

the error message looks different for me:

            "memoryview: destination format must be a native "
            "format prefixed with an optional '@'");

I think it's fine.

I did replacement for comments, though.

@read-the-docs-community
Copy link
Copy Markdown

read-the-docs-community Bot commented May 7, 2026

Documentation build overview

📚 cpython-previews | 🛠️ Build #32635400 | 📁 Comparing b4d4499 against main (612140e)

  🔍 Preview build  

59 files changed · + 1 added · ± 58 modified

+ Added

± Modified

@skirpichev
Copy link
Copy Markdown
Member Author

CC @vstinner

Documentation now rendered.

Copy link
Copy Markdown
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

I would prefer to keep "format" in struct. For example, struck.pack() first parameter is called "format" and its documentation calls it "format string": https://docs.python.org/dev/library/struct.html#struct.pack. So I suggest replacing "Format Characters" with "Format Strings".

Comment thread Doc/library/ctypes.rst Outdated
Co-authored-by: Victor Stinner <vstinner@python.org>
Comment thread Doc/library/struct.rst Outdated
@vstinner vstinner enabled auto-merge (squash) May 11, 2026 12:41
@vstinner vstinner merged commit ef87731 into python:main May 11, 2026
55 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in Docs PRs May 11, 2026
@skirpichev skirpichev deleted the improve-pep3118-docs-p1/149402 branch May 11, 2026 13:06
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.

3 participants