Skip to content

PEP 526: Fix name mangling example - #5138

Merged
JelleZijlstra merged 1 commit into
python:mainfrom
jang-hs:pep-526-mangling-example
Sep 23, 2026
Merged

JelleZijlstra merged 1 commit into
python:mainfrom
jang-hs:pep-526-mangling-example

Conversation

@jang-hs

@jang-hs jang-hs commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Fixes #3062.

The example annotates __points at module level, but name mangling only happens inside a class body, so it is stored as '__points' and the '_Player__points' output shown never appears. The mangled entry was added in c51c018 to illustrate the "(mangled if private)" wording, so this keeps that intent: the annotation moves into Player and the example prints Player.__annotations__ as well. I ran the updated snippet and it prints exactly the two dicts shown.

  • Change is either:
    • To a Draft PEP
    • To an Accepted or Final PEP, with Steering Council approval
    • To fix an editorial issue (markup, typo, link, header, etc)
  • PR title prefixed with PEP number (e.g. PEP 123: Summary of changes)

Name mangling only applies inside a class body, so a module-level
``__points: int`` is stored as ``'__points'``, not ``'_Player__points'``.
Move the annotation into the class and print its ``__annotations__``.
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 pep-previews | 🛠️ Build #34709541 | 📁 Comparing 6577a94 against latest (7d5ca36)

  🔍 Preview build  

1 file changed
± pep-0526/index.html

@ilevkivskyi ilevkivskyi 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.

Yeah, looks good. (Not sure if I should merge this or wait for the PEP editors)

@JelleZijlstra
JelleZijlstra merged commit e03cf3e into python:main Sep 23, 2026
5 checks passed
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.

PEP 526: Name mangling doesn't take place inside the body of a module

3 participants