Try to search your question here, if you can't find : Ask Any Question Now ?

subclassing a message to add additional behavior

HomeCategory: stackoverflowsubclassing a message to add additional behavior
Avatarpushpa asked 3 months ago

Not sure why this isn’t working, I want to subclass a message and add additional behavior:

import data_pb2 as pb2

class Status(pb2.Status):
    def __init__(self, streamer, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.streamer = streamer

    def __setattr__(self, key, value):
        super().__setattr__(key, value)
        self.streamer.send_update()

When someone changes the pb2.Status message I want send_update to be called.
This is the unhelpful error message I’m getting:

Traceback (most recent call last):
  File "server.py", line 62, in <module>
    class Status(pb2.Status):
  File "C:AppDataLocalcondacondaenvssateclibsite-packagesgoogleprotobufinternalpython_message.py", line 126, in __new__
    descriptor = dictionary[GeneratedProtocolMessageType._DESCRIPTOR_KEY]
KeyError: 'DESCRIPTOR'
1 Answers
Best Answer
AvatarFernando answered 3 months ago
Your Answer

15 + 14 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com