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: __ private members/name mangling in classes #853

Open
MrApplejuice opened this issue Jun 6, 2023 · 1 comment
Open

Feature: __ private members/name mangling in classes #853

MrApplejuice opened this issue Jun 6, 2023 · 1 comment

Comments

@MrApplejuice
Copy link

Sorry, I would expect that this probably documented but I just cannot find it:

https://docs.python.org/3/tutorial/classes.html?highlight=name mangling#private-variables

Short question: Is this supported in some way? Or are there plans to support it?

It seems to be such a core-feature of Python that I kind of feel stupid to ask, I would bet that it was decided to not implement that feature somewhere/somehow, but I cannot find a reference to that decision or if it even was made?

To me this would be a very awesome feature, because it is for me the feature that avoids naming collisions in classes for something like Class-Mixins. I am reviving an old project of mine which consists converting an old piece of Python code to a web-capable implementation, and this would make those conversion efforts a LOT more convenient.

@MrApplejuice
Copy link
Author

Background:

class HighscoreMixin:
    pixi = None

    __my_value = 1

    def __init__(self):
        self.__my_second_value = 2
        print(list(sorted(dir(self))))

    def update_highscore(self, new_score):
        pass

Outputs:

 [..., '__my_second_value', '__my_value', ...]

Which is not name mangled.

PS: Looks like a game, but it is actually an scientific experiment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants