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

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

Closed
wallrj opened this issue Jun 19, 2014 · 3 comments
Closed
Milestone

Comments

@wallrj
Copy link

@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
Copy link
Owner

@hynek 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
Copy link
Author

@wallrj 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
Copy link
Owner

@hynek hynek commented Aug 7, 2014

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

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

Successfully merging a pull request may close this issue.

2 participants