You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Not a bug per se but a curiosity. I'm currently using pydantic to build some nested models in order to give the user the possibility to add extra configurations. At the same time I want to render these models evented by adding the SignalGroupDescriptor.
What I Did
For type hinting purposes I did the following:
frompsygnalimportEmissionInfo, SignalGroupDescriptorfrompydanticimportBaseModelfromtypingimportClassVarclassMyModel(BaseModel):
message: strevents: ClassVar[SignalGroupDescriptor] =SignalGroupDescriptor()
classMyChildModel(MyModel):
child_message: strevents: ClassVar[SignalGroupDescriptor] =SignalGroupDescriptor()
classModelWrapper:
def__init__(self, model: MyChildModel) ->None:
self.model=modelself.model.events.connect(self.on_event)
defon_event(self, info: EmissionInfo):
print(f"Signal {info.signal.name} received with data {info.args}")
child=MyChildModel(message="Hello", child_message="World")
wrapper=ModelWrapper(child)
wrapper.model.message="Goodbye"wrapper.model.child_message="Universe"
It seems to work. Then I realized: what happens if I remove events from the child model? Apparently, if you comment it out, it still works.
My ignorance in the matter is obvious, so I'm just checking in if this behavior may cause issues in the future or if it's an acceptable usage.
EDIT: the idea is that these models are singletons, a.k.a. they're created only once by the application and the user just configures a new model and passes it to the application which builds it, the constructor can't and shouldn't be called by the users themselves.
The text was updated successfully, but these errors were encountered:
definitely an acceptable usage, and more or less the same general idea that I'm trying to automate in #298 (in terms of finding and connecting child events without the need for the __init__)
the general pattern of connecting a signal emission to a re-emission of another signal is fully supported
Description
Not a bug per se but a curiosity. I'm currently using pydantic to build some nested models in order to give the user the possibility to add extra configurations. At the same time I want to render these models evented by adding the SignalGroupDescriptor.
What I Did
For type hinting purposes I did the following:
It seems to work. Then I realized: what happens if I remove events from the child model? Apparently, if you comment it out, it still works.
My ignorance in the matter is obvious, so I'm just checking in if this behavior may cause issues in the future or if it's an acceptable usage.
EDIT: the idea is that these models are singletons, a.k.a. they're created only once by the application and the user just configures a new model and passes it to the application which builds it, the constructor can't and shouldn't be called by the users themselves.
The text was updated successfully, but these errors were encountered: