From 9c34491e209b3ccc99a5f23e14499bcdcab70ce8 Mon Sep 17 00:00:00 2001 From: Jan Pochyla Date: Wed, 1 Jun 2016 14:31:49 +0200 Subject: [PATCH] self.__dict__ does not work properly in uP, workaround --- src/lib/protobuf/protobuf.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib/protobuf/protobuf.py b/src/lib/protobuf/protobuf.py index d23ee34b7..9c46750e5 100644 --- a/src/lib/protobuf/protobuf.py +++ b/src/lib/protobuf/protobuf.py @@ -200,7 +200,10 @@ class Message: def __init__(self, message_type, **fields): # Initializes a new instance of the specified message type. self.message_type = message_type - self.__dict__.update(fields) + # In micropython, we cannot use self.__dict__.update(fields), + # iterate fields and assign them directly. + for key in fields: + setattr(self, key, fields[key]) def dump(self, fp): # Dumps the message into a write-like object.