-
-
Notifications
You must be signed in to change notification settings - Fork 383
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
Validating, __init__-based assoc. #124
Conversation
Current coverage is 100% (diff: 100%)@@ master #124 diff @@
====================================
Files 8 8
Lines 502 511 +9
Methods 0 0
Messages 0 0
Branches 110 112 +2
====================================
+ Hits 502 511 +9
Misses 0 0
Partials 0 0
|
Nah we don’t have to support both. I had a slightly different approach in mind (which I honestly forgot :)) which would’ve given it us for free. Other than that I don’t have much to add. The performance gains look awesome! We can always add support for underscore names if enough people complain. But removing is much harder. |
Just to clarify, this implementation supports underscore names, i.e. the setter syntax. (For backwards compatibility.) |
Oh, so it doesn’t support the |
No, this is setter only. I figured from the issue this is what you wanted. I mean, this implementation is a little more complex and a little slower than the init syntax, so if that's what you want I can revert it. |
No it’s alright. Backward compatibility FTW. Please finish up. :) |
I’ll have to meditate on the backward-incompatible part. To me, this is a bug fix because I think everyone would expect it to behave this way. The point about Hmmmm. |
In any case:
|
The usual guidance is in Twisted when people start fretting about changed behavior is "new names are cheaper than you think". Instead of FWIW I have always hated |
( I should also note, though, that this is a good change. I was just reviewing a PR on https://github.com/rackerlabs/otter where I was lamenting the odd behavior of |
I'm still with the inlaws for the holidays and away from my home computer. I've been thinking of the name, though. I think Glyph is right and we should leave assoc as is, deprecate it, and think of a better name for this implementation. What's actually happening is:
'Copy' or 'clone' are okay but they don't really mesh well with the fact the original object is being changed. In fact, they kinda imply the object is not being changed at all. In my opinion. How about 'recons', as in 'reconstruct' or 'reconstitute'? We're breaking the instance into parts (asdict), then putting it back together, changed.
( Another idea is |
All of the various derivatives of the word "change" - "modify", "mutate", etc, imply the thing itself is changing, as opposed to a new thing coming into existence. But wait - in that sentence I used the word "derivative" to describe exactly that sort of thing! This might be too cutesy given its overlap with other terms, especially math terms, but I could see Thoughts? |
I agree that derive is the first name that I could sort of live with but I'm not happy with it. There has to be some term that isn't some obscure math/FP lingo and that expresses precisely what we need!? I really don't want it to be unclear what it's about. |
"convolve"? :) |
or perhaps "comprise"? |
OK one more rule: I don’t have to look it up in a dictionary. ಠ_ಠ |
|
FTR, pyrsistent seems to have |
Except for the fact that "transform" also means "change" in the "mutate the existing object" sort of way. |
Actually this might be the best bet. Consider that even the average 7-year-old knows that Pokémon have "evolutions".* *: except of course what pokémon actually have are metamorphoses, which are destructive changes, but as a real species "evolves" it involves creating lots of new instances |
I was rather thinking about evolution which usually happens over generations. Humans evolved from ape. There was no ape who suddenly liked computers. |
So I believe we’ve agreed on deprecating assoc as it is and implementing a new |
Alright, so we're settled on evolve? I prefer derive, but the boss has the final say of course :) I'll put together a new PR soon-ish. Are we deprecating assoc though? |
Yay! Evolvulation! |
I can live with derive too...I guess I'll have to check a thesaurus or something. :-/ |
Sorry, I didn't mean that to seem critical of the choice of "evolve", I just found the quote evocative :).
|
I like both for different reasons. :| |
Working on this a little. The docs state:
Ok, let's raise a DeprecationWarning, as per the docs.
Nothing happens. Pop over to https://docs.python.org/3.6/library/warnings.html:
Doesn't this make DeprecationWarning basically useless? Who runs their Python with -W? Not me. In fact I had to Google how to enable warnings at all (it's python -Wd). |
Regarding the name, IIUC (I have very little experience with the library, so maybe not), this operation is similar to namedtuple._replace, in which case |
@Tinche Django advises its users to enable warnings when updating, at least: https://docs.djangoproject.com/en/1.10/howto/upgrade-version/#resolving-deprecation-warnings |
Deprecation WarningsWe should add documentation on them to the backward compatibility page. NamingI’m not a fan of So far we have:
I’ve spend some time in a thesaurus and found nothing better. Anyone more 🎨 ? |
If I may adjust my 🚲🏠🎨: I think you're right about "derive". A subclass is, formally, a derived class. So if, as its original submitter, I can withdraw it from consideration, I will do so.
|
Yep. Huge mistake on the part of Python core if you ask me. Still hoping they'll reverse it.
Me! Or, well, not exactly. But trial turns on deprecation warnings by default, and if you drop this gem into your .bashrc while you're developing:
you don't need to actually inject the command-line arg. |
The reason is explained in the namedtuple docs:
In attrs it's a module function so it's not a problem. |
Yeah namedtuple's underscore methods is one of the reasons why attrs uses functions wherever possible. |
Tin! Let's evolve attrs! |
Closing in favor of #135. |
Here is an
__init__
-basedassoc
implementation that handles private attributes.Using the same three classes from #116, I've done benchmark runs for all-public and all-private attributes on the classes. Private attributes add a slight overhead now, the old implementation was unaffected. Underscores in front of class names indicate private attributes were used.
I'm pretty sure we could handle the users supplying both private and public attribute names (i.e. both setter and init syntax) with a tiny performance cost, but is it worth it? First of all,
second, could there be corner cases? I can't think of any (
isn't one of them, fortunately :) but maybe there are some?
Doc change and CHANGELOG entry to come when we're satisfied with the implementation.