Generate __init__ with converters inline. #80
Conversation
Current coverage is 100% (diff: 100%)@@ master #80 diff @@
===================================
Files 8 8
Lines 398 413 +15
Methods 0 0
Messages 0 0
Branches 88 88
===================================
+ Hits 398 413 +15
Misses 0 0
Partials 0 0
|
Omg |
Before I have closer look at your abomination, please add a changelog entry. :) |
Done. |
At this point I feel like we should write some integration test for |
Not really sure comparing strings of source code will be a better test than testing the actual behavior. I guess we could assert that the generated init is the most optimal it can be, but we'd also have to take into account some internal stuff, like the __attr_validator_x and __attr_convert_x globals. |
It's kind of a shame there aren't any libraries for generating Python source code. Or at least I can't find any. Libraries that would expose objects and just let you render to source at the end, instead of glueing strings together. Maybe I'll write something. |
I’m not really saying we should do it. I’m just saying that function haunts me at night. ;) |
Here's some more horror. :)
The gains are actually more than I expected.
Frozen classes:
I was actually a little weirded out, but the tests pass and playing around in the repl, it seems to work.
I thought the gains would be greatest with about 50% attributes with converters on them, but no, even with all attributes having converters, I see more than double the speed.