-
-
Notifications
You must be signed in to change notification settings - Fork 370
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
attr default based on other attributes #165
Comments
Hi, for now I suggest using |
I have wanted to do this several times. For example, you have a test of a function which takes many inputs. You want to test this function with many different cases. So (of course) you create a quick e.g.
What I'd want, following the ad-hoc validators example, is something like this:
This is sensitive to the initialization order. However, if you have a stateful factory, the order is already important, so this is not new. And the natural order is the definition order which is intuitive. Another issue is that this makes it possible to specify multiple defaults. I would just raise an error if this is detected. Final issue I can think of is that an occasional user might confuse this with a property, while it does not behave like a property:
But I think "default" is clear on the behavior it has. |
At first glance I like the proposed API :) |
I guess we could have a lot fun with decorators based on |
I think I want this in 17.1 but it entirely depends on the goodwill of reviewers (most likely @Tinche – I gotta shanghai some innocent souls at PyCon). |
Hi!
I have unsucessfully tried to define a default value by referencing other attributes. I'm sure the code below doesnt' work for some obvious or fundamental reason, but I would be grateful for comments on how to do something like it:
I included the
.strftime()
conversion to highlight thatname
doesn't see a float and a date, but a_CountingAttr
object, hence I get an AttributeError (and a TypeError forsome_number * 100
). Since I can't reference self either, what would be the correct way to do this?The text was updated successfully, but these errors were encountered: