Optionally use __slots__ for payload members - #259
Open
misakwa wants to merge 12 commits into
Open
Conversation
added 5 commits
November 18, 2016 01:35
- Expose using slot based generated code to load entry points
- Add first tests
- TODO:
- Fix possible cache poisoning when loading slot vs no slot structs
- Add tests for above
- Add pickling tests for slot based structs
Author
|
There are still a few questions and some cleanup to be done, but I think this should get the conversation started. |
- Replace class with a newer one with slot fields - Implement subclass and instance checks
Contributor
|
Feature accepted. Update this issue later. |
During the first creation of the loaded class with slots, a new class is
inserted into the inheritance chain to ensure that the slot fields are defined.
This is done because of the need to create an empty struct during the
parsing phase and fill it in later - slots require the fields to be known before hand.
All checks on the new replacement class will have it looking like the
original except an equality comparison between the replaced class and
its replacement.
>>> import thriftpy
>>> ab = thriftpy.load('addressbook.thrift', use_slots=True)
>>> ab_inst = ab.AddressBook()
>>> ab_inst.__class__ == ab.AddressBook # will return False
>>> # all other checks should work as expected
>>> isinstance(ab_inst, ab.AddressBook) # will return True
>>> issubclass(ab_inst.__class__, ab.AddressBook) # will return True
In order to get pickling to work as expected, a new extension type is
registered with copyreg (copy_reg for py2x) to avoid pickling errors.
Author
|
I have updated the implementation to support all types of objects as well as the recursive case. The service args and results are now created with slots as well. |
misakwa
force-pushed
the
fix/optimize-payload
branch
from
November 22, 2016 12:58
ba74089 to
afd9acd
Compare
misakwa
force-pushed
the
fix/optimize-payload
branch
from
November 22, 2016 13:37
7f3f6bd to
682e191
Compare
Author
|
This is now ready for review. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #198