Added an .empty() function to the objects, fixes to msgs_ack

The .empty() function returns an "empty" instance of the object
(attributes set to None). This is used rather than using reflection.

The msgs_ack handling broke stuff (InvokeWithLayer when there were
updates), so this is now handled; yet there may be a better fix
This commit is contained in:
Lonami
2016-09-26 17:16:15 +02:00
parent ded655911e
commit 77aa37d2ad
4 changed files with 25 additions and 13 deletions

View File

@@ -117,14 +117,9 @@ class BinaryReader:
# If there was still no luck, give up
raise TypeNotFoundError(constructor_id)
# Now we need to determine the number of parameters of the class, so we can
# instantiate it with all of them set to None, and still, no need to write
# the default =None in all the classes, thus forcing the user to provide a real value
sig = inspect.signature(clazz.__init__)
params = [None] * (len(sig.parameters) - 1) # Subtract 1 (self)
result = clazz(*params) # https://docs.python.org/3/tutorial/controlflow.html#unpacking-argument-lists
# Finally, read the object and return the result
# Create an empty instance of the class and
# fill it with the read attributes
result = clazz.empty()
result.on_response(self)
return result