Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: alias names with starting with __ should be mangled when attached to a class #28

Open
mxndtaylor opened this issue Jun 10, 2024 · 0 comments
Assignees

Comments

@mxndtaylor
Copy link
Owner

Is your feature request related to a problem?

python's mangling system is convenient, but with this method of aliasing member, we do not mangle the alias names.

leading to issues like this:

class Foo:
    @aka.valiases("__mangled_alias")
    def __mangled_initial(self):
        return "val"

print(Foo().__mangled_alias())
# prints "val"

I would expect the above to fail, and leave the alias's name as _Foo__mangled_alias instead, so that this succeeds:

class Foo:
    @aka.valiases("__mangled_alias")
    def __mangled_initial(self):
        return "val"

print(Foo()._Foo__mangled_alias())
# prints "val"

Describe the solution you'd like

if alias.__set_name__ gets a name that has leading __ (with at most 1 trailing _), then mangle the alias's name based on owner.__name__.

ex:

class Foo:
    prop = 1

prop_alias = alias(alias_name="__prop")
prop_alias.attach(Foo)
assert Foo()._Foo__prop == 1

Additional context

We might want to add a parameter no_mangle or such that disables this behavior

@mxndtaylor mxndtaylor self-assigned this Jun 10, 2024
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

No branches or pull requests

1 participant