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
Erroneous duplicate argument error #244
Comments
i do wonder if there is ever an actual case where such a attrbute naming adds value, |
I'll write up my use-case after lunch. But for now I can say it feels a bit weird having the
|
Okay... here us my use case (perhaps justified, perhaps not). I'm extracting GitLab information using python-gitlab. To accomplish this, I have two different kinds of attributes. Ones that will be serialized, and ones that won't. They are differentiated by whether they have a leading underscore or not. # I serialize it like this...
d = attr.asdict(extract, filter=lambda a, v: not a.startswith('_'))
json.dump(d, fp, indent=2) # produces exactly what will be fed into JIRA So... that is the need for the underscore (to mark whether to serialize it or not). Now you may be wondering about why have two fields with the same name? Well, these @attr.s
class Comment:
author = attr.ib()
message = attr.ib()
@attr.s
class Issue:
comments = attr.ib() # list of the above attr.s Comment objects
_comments = attr.ib() # list of underlying GitLab Comment objects |
YYMV, but I think it's a bad pattern to tightly couple the names of symbols in a class def to your serialization format. This probably won't be the only time that this apparent simplicity bites you. In this case, you are competing with |
this line makes it impossible to have a class like the following. I believe it should be possible.
The text was updated successfully, but these errors were encountered: