PEP 526: Fix name mangling example - #5138
Merged
Merged
Conversation
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__``.
jang-hs
requested review from
gvanrossum,
ilevkivskyi and
lisroach
as code owners
September 23, 2026 02:40
Documentation build overview
|
ilevkivskyi
approved these changes
Sep 23, 2026
ilevkivskyi
left a comment
Member
There was a problem hiding this comment.
Yeah, looks good. (Not sure if I should merge this or wait for the PEP editors)
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3062.
The example annotates
__pointsat 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 intoPlayerand the example printsPlayer.__annotations__as well. I ran the updated snippet and it prints exactly the two dicts shown.PEP 123: Summary of changes)