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

Allow initialiser arguments to be mapped to alternative (private) attribute names #6

Closed
wallrj opened this Issue Jun 19, 2014 · 3 comments

Comments

Projects
None yet
2 participants
@wallrj

wallrj commented Jun 19, 2014

In Twisted we try hard to limit the public API in new classes so it would be nice if with_init had some way to map an argument name to an alternative private attribute name.

In fact it might even be enough to have a rule that argument names beginning with _ would be stored as private attributes but supplied without the _ prefix.

twisted.python.util.FancyStrMixin has a horrible system where you can supply a tuple of (attr_name, display_name). I suppose you could do something like that here.

Or add a new Attribute class with an argument_name option...and then allow that to be supplied to the characteristic decorators...if you see what I mean.

@hynek

This comment has been minimized.

Owner

hynek commented Jun 19, 2014

Yep, I thought about that before.

I guess I would go two ways:

  1. Each decorator accepts an Attribute class as you suggest.
  2. @attributes additionally adds a convenience argument like private=False that automagically transforms all into _attr if true since that's a rather common case.

Makes sense?

@wallrj

This comment has been minimized.

wallrj commented Jun 20, 2014

2 @attributes additionally adds a convenience argument like private=False that automagically transforms all into _attr if true since that's a rather common case.

I think this second option would be convenient, but what I meant in my original comment was that characteristic could implement a policy of always removing leading _ when looking for keyword argument names.

@exarkun is always reminding us that there's no such thing as a private function argument, so maybe he'd approve of that policy.

@hynek hynek added this to the 0.2 milestone Jun 20, 2014

@hynek hynek modified the milestones: 14.1, 14.0 Aug 7, 2014

@hynek

This comment has been minimized.

Owner

hynek commented Aug 7, 2014

I think I’ll move this into 14.0 while waiting for glyph sacrificing goats in #9.

@hynek hynek closed this in #13 Aug 17, 2014

hynek added a commit that referenced this issue Aug 17, 2014

Merge pull request #13 from hynek/private-attrs
Add keyword-aliasing for underscores

Fixes #6.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment