-
-
Notifications
You must be signed in to change notification settings - Fork 374
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
Add takes_self to Factory and @_CountingAttr.default #189
Conversation
Codecov Report
@@ Coverage Diff @@
## master #189 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 9 9
Lines 560 579 +19
Branches 124 126 +2
=====================================
+ Hits 560 579 +19
Continue to review full report at Codecov.
|
This is somewhat evil, but have you considered counting the number of arguments to the factory function, instead of taking |
Not only did I consider it, I've even implemented it. :) But it seemed too magicy with too many weird edge cases. It's always possible to add magic but it's impossible to remove it. And I reckon the decorator approach will be the main one anyways... |
OK, I'm starting looking at this. Let's talk API first :) The
Another suggestion. I've been mulling over #178 with spare brain cycles. I've come to realize the wordy
could be rewritten like this:
To me this reads much better and is possible today. Honestly I think I would prefer this rather than allow both What if we actually implemented
|
I like the idea of a smart call. It solves two problems at once and doesn't risk any backward incompatibilities. But that should be a separate PR, right? Let's merge this first and implement call on top of it. I promise there won't be 17.1 w/o call. ;) |
Hm, maybe it shouldn't be |
👍 to separate PR. As for
You can't really decorate a value so I'm OK with the fact the decorator is applied to a method and the I'll take a look at the implementation first thing I have the chance. You said you wanted this before PyCon, that's on Wednesday? |
Yeah I travel on Wednesday but accordingly my Tuesday is rather dense so sooner would be better. :) |
Given the following test class:
this init gets generated:
which is fine, nothing wrong with it. However, we can speed it up, as always, by shifting work. This init does a dict lookup (on attr_dict), then an instance look up on that, then a method call. This is unnecessary. If we just inject the factory into the globals and generate an init like this:
my benchmark goes from 1.69 us +- 0.05 us to 1.38 us +- 0.07 us, which is significant (~22% speedup). There, now the ball is in your court :p |
Aaaand it’s back to you fine sir! |
The renaming of |
Now this is a biggie but I believe it’s worth it for 17.1. There should be no performance penalty but it’s a feature that people have been yearning for since day one. :)
Let me know what you think, contains some boy scouting. Most notably the completely hosted markup in api.rst around evolve. Also WTF was with local dunder variables in methods? I suppose copy pasta?
This enables the following:
Now calling
C()
gives youC(x=1, y=2, z=3)
.Fixes #165