-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal for alternate SignalGroup pattern #267
Comments
cc @andy-sweet, @Czaki, @jni ... inasmuch as napari is considering using psygnal for its events, this decision would affect you and I'd welcome your input. Trying to boil it down as briefly as possible: Are you ok with replacing As mentioned above by @getzze, this could be done in a new class (e.g. |
one more thought, thinking about deprecation: The most likely "surprise" would be someone trying to connect to everything using |
At this moment my main worry is app-model context that is cached now and require to be connected to some event/signal to update. At second, I do not understand why |
can you please point more directly? I'm not sure I'm seeing the issue
it can, that's what I meant when I said: "We could always add a single deprecated attribute on this new class "connect" to catch this use case and inform the user without direct breakage. And the only time that would break is if they had an event named connect (which is probably very unlikely)" |
Why deprecated?
As I checked the code, I'm not sure if the connect signal could exit. But maybe I know the wrong order.
This is your instruction from the time of implementing app-model in napari. https://napari.org/dev/guides/contexts_expressions.html#updating-contexts |
doesn't have to be, that's what the discussion is for 😂 ... the motivation, as stated above, is to get as many names off of signal group as possible, since it's a likely target for name collision. And, as mentioned, if we left a method
yep, I remember that bit... but you said "my main worry is app-model context that is cached now and require to be connected to some event/signal to update." Can you help me out a little bit and be slightly more explicit? For example, tell me what specific cache you're talking about; give me an example of the type of scenario you're talking about. You know, elaborate a little bit; maybe provide a bit of pseudocode, something so I don't have to guess exactly what your worry is |
So maybe use
For example this part of code in napari: Where the context needs to be updated each time when the state of layer list is changed. |
what need to manually curate the list of events? |
yes. If I'm wrong then I have no problem with this proposal. |
I don't have a strong opinion here, other than
Did I miss any other decision points? |
the single name would be modifiable with a type hint (see implementation in #269). currently, I'm using
all methods will pass through with a deprecation warning (see #269).
I currently do have it deprecated in #269... but we can revisit this. I think it's the better way to go personally, but can pull that back if folks want. Note that
that was already in the proposal, and yes, is being implemented. |
I was being flippant of course, but I think it takes a fair bit of programming background to leap from agg to aggregator and then from aggregator to ok this is all the child events. But anyway we are in agreement. 😊
How many of these are really user-facing? I think as a user, connect and disconnect would be the main things I would interact with on a signal group, as well as |
there's also |
Sorry, I missed the discussion here, but the main decisions and actions seem great. I like Without thinking too hard, I don't love exposing |
it's not only there to provide |
This is meta-issue collecting thoughts and proposals about solving name conflicts in SignalGroups.
(see also)
The primary problem stems from the fact that
SignalGroup
inherits fromSignalInstance
(which has a fair number of attributes, likename
, etc...)SignalGroup
are determined by the user, and accessible as attributesSignalGroup().name
)As a little history, the pattern of inheritance was originally borrowed/inspired from vispy's
EmitterGroup
(akin toSignalGroup
, which inherits fromEventEmitter
(akin toSignalInstance
). I'll note that vispy simply forbids you to use a name that conflicts. But I don't think that's an acceptable approach for psygnal, particularly if we want to support evented dataclasses (which are almost certainly going to have fields likename
at some point).At the moment, I'm leaning towards a new class entirely, as proposed by @getzze in #262 (comment) and copied below. This new class would be a plain container with minimal private attributes, preventing name conflicts. The primary thing we lose there by not inheriting from
SignalInstance
is that you can't connect to the group class itself using, for exampleevents.connect
... but that's easily solveable by either adding an aggregating signal (e.g.events.agg.connect()
), or a special method (e.g.events.connect_all()
... risking name conflicts)Originally posted by @getzze in #262 (comment)
I was thinking that
SignalGroup
could be a container class instead.Positive:
__getitem__
, withevents["foo.sig"]
Negative
events.connect
would be longer,events.agg.connect
SignalContainer
, and do not touchSignalGroup
so people could choose to use one or the other.The text was updated successfully, but these errors were encountered: