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

How Name Mangling is supposed to work in python-attrs? (double leading underscores) #927

Closed
txemi opened this issue Mar 5, 2022 · 4 comments

Comments

@txemi
Copy link

txemi commented Mar 5, 2022

Converting some classes to atts I found that there is not a documented way to work with name mangling. I am aware of pythonic way in wich forcing is not common, trusting responsible adults instead it is and name mangling is not commonly used; but anyway I sometimes use it for preventing accidents where it is clear that some data should not be accesed from outside the class.

What has python-atts to say about this? (Direct approach does not work, I already tried and constructor with keyword fails with "TypeError: missing a required argument")

@hynek
Copy link
Member

hynek commented Mar 9, 2022

attrs automatically removed leading underscores when determining the argument names: https://www.attrs.org/en/stable/init.html#private-attributes

@txemi
Copy link
Author

txemi commented Mar 10, 2022

Sorry, I did not undertand. May I use this?

@define class C: __x: int

It did not work when I tried to init __x from constructor.

attrs automatically removed leading underscores when determining the argument names: https://www.attrs.org/en/stable/init.html#private-attributes

@hynek
Copy link
Member

hynek commented Mar 11, 2022

Ah yeah I'm sorry I misread on my phone an answered from memory.

This is in fact currently not supported and is a dupe of #619.

As you wrote, using name mangling is rather uncommon nowadays, so nobody came forward to push for a proper implementation.

@wbolster
Copy link
Member

closing as dup to keep discussion centralized; see #619

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

3 participants