-
-
Notifications
You must be signed in to change notification settings - Fork 385
option for disable strips the underscores #391
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
Comments
You can have an In [1]: import attr
In [2]: @attr.s
...: class C:
...: _id = attr.ib()
...:
In [3]: C(1)
Out[3]: C(_id=1) |
Problem is in In [1]: import attr
In [2]: @attr.s
...: class C:
...: _id = attr.ib()
...:
In [3]: C(**{'_id': 1})
Traceback (most recent call last):
File "<input>", line 1, in <module>
TypeError: __init__() got an unexpected keyword argument '_id' How to add |
|
Furthermore, the documentation states that "There really isn’t a right or wrong, it’s a matter of taste." but one way is not allowed in the software so there is clearly a wrong way to do it according to attrs. This is misleading. |
This issue has come up in some generated code before, for example like this. @attr.s
class A:
_ = attr.ib()
File "<attrs generated init __main__.A>", line 2
self._ =
^
SyntaxError: invalid syntax |
Any updates on this topic? |
A side note, you can use import attr
import cattr
@attr.s
class C:
_id = attr.ib()
cattr.structure({'_id': 1}, C) |
This still doesn't allow for having both a |
closing in favour of #945, which is newer, but has many more details and proposals. |
Add an option to disable strips the underscores
http://www.attrs.org/en/stable/init.html#private-attributes
I need to create class with
_id
attribute and this is not possible with attrs at this momentThe text was updated successfully, but these errors were encountered: