Repository navigation
Mangle private names when evaluating f-string values inside a class - #2861
Merged
alexmojaki merged 3 commits intoNov 23, 2026
Merged
Conversation
Inside a class body the compiler rewrites `self.__x` to `self._ClassName__x`. The f-string magic compiles each value on its own, so the second evaluation looked up the unmangled name, raised AttributeError or NameError, and was reported as an internal error (re-raised under pytest). Apply the same rewrite to the names in the compiled value and format spec.
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 2 files
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 1 file (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
View guided diff | Re-trigger cubic
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 #2860.
When the f-string sits inside a class body,
compile_formatted_valuenow applies CPython's private-name mangling to the names in the compiled value and format spec. It uses the innermost enclosing class, found through the parent linksexecutingsets. F-strings outside a class are unchanged. Zero-argsuper()inside an f-string still fails, but that has a different cause and isn't touched here.test_private_names_in_fstringcovers a private attribute, a private class attribute and a private local in a format spec, and fails on main with the issue'sAttributeError. Full suite (3687 passed),make lintandmake typecheckare green.Drafted with Devin (Claude Opus 5.5, SWE-2).