Skip to content

Do not mangle the __name__ of private functions and classes - #2203

Merged
slozier merged 3 commits into
IronLanguages:mainfrom
deronnax:fix-private-def-names
Dec 6, 2026
Merged

slozier merged 3 commits into
IronLanguages:mainfrom
deronnax:fix-private-def-names

Conversation

@deronnax

@deronnax deronnax commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

In a class, def __f and class __C got a mangled __name__ (_Outer__f), and the private names inside class __C were mangled with the wrong prefix (_Outer__C__x instead of _C__x).

The parser mangled the name itself. The name of the definition is now kept as written, and only the variable it is bound to (the new BindingName) is mangled.

Test: test_private_function_and_class_names in tests/suite/test_class.py.

Written with Claude Sonnet 5.5, reasoning effort: medium.

The name of a private function or class defined in a class was mangled when
parsing, which also changed its __name__ and, for a class, the prefix used to
mangle the private names inside it. Mangle only the name of the variable the
definition is bound to.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@slozier slozier left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the PR! The FlowChecker should also be updated to use BindingName, otherwise private local defs are no longer marked as assigned and get unnecessary unbound checks.

Not for this PR: longer term, mangling should probably move from the parser into the binder...

deronnax and others added 2 commits December 6, 2026 04:09
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@deronnax

deronnax commented Dec 6, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. FlowChecker now defines BindingName for private functions and classes (b1b3ddd), and I merged main to resolve the conflict in tests/suite/test_class.py. The cs, IronPython and CPython test categories pass locally with net11.0, except test_fd, which also fails without this change.

@slozier slozier left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!

@slozier
slozier merged commit 259ce3c into IronLanguages:main Dec 6, 2026
41 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.

2 participants