Skip to content
This repository was archived by the owner on Dec 10, 2018. It is now read-only.

Commit 4032763

Browse files
author
misakwa
committed
fix service result slots
1 parent 1a3b1bd commit 4032763

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

tests/test_hook.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,8 @@ def test_load_slots():
122122
args_slots = thrift.AddressBookService.get_phonenumbers_args.__slots__
123123
assert args_slots == ['name', 'count']
124124

125-
# XXX: service result will have their slot list empty until after they are
126-
# created. This is because the success field is inserted after calling
127-
# _make_struct. We could hardcode a check in the metaclass for names ending
128-
# with _result, but I'm unsure if its a good idea. This should usually not
129-
# be an issue since this object is only used internally, but we can revisit
130-
# the need to have it available when required.
131-
result_obj = thrift.AddressBookService.get_phonenumbers_result()
132-
assert result_obj.__slots__ == ['success']
125+
result_slots = thrift.AddressBookService.get_phonenumbers_result.__slots__
126+
assert result_slots == ['success']
133127

134128
# should be able to pickle slotted objects - if load with module_name
135129
bob = thrift.Person(name="Bob")

thriftpy/parser/parser.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,8 @@ def _make_service(name, funcs, extends, use_slots=False):
833833
result_cls.default_spec.insert(0, ('success', None))
834834
gen_init(result_cls, result_cls.thrift_spec, result_cls.default_spec)
835835
setattr(cls, result_name, result_cls)
836+
# default spec is modified after making struct so add slots here
837+
result_cls.__slots__ = [f for f, _ in result_cls.default_spec]
836838
thrift_services.append(func_name)
837839
if extends is not None and hasattr(extends, 'thrift_services'):
838840
thrift_services.extend(extends.thrift_services)

0 commit comments

Comments
 (0)