feat: add signal aliases on SignalGroup#299
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #299 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 22 22
Lines 1972 2009 +37
=========================================
+ Hits 1972 2009 +37 ☔ View full report in Codecov by Sentry. |
CodSpeed Performance ReportMerging #299 will improve performances by 14.18%Comparing Summary
Benchmarks breakdown
|
|
All tests pass, there is just a small performance regression. This is good to review. |
|
at first glance I'm impressed! will review more thoroughly soon. thanks again @getzze |
src/psygnal/_group.py
Outdated
| def get_signal_by_alias(self, name: str) -> SignalInstance | None: | ||
| sig_name = self._psygnal_aliases.get(name, name) | ||
| if sig_name is None or sig_name not in self: | ||
| return None | ||
| return self[sig_name] |
There was a problem hiding this comment.
hey @getzze, I think this is probably my only question (in an extremely nice PR). I can see why you did it this way as opposed to modifing __getitem__ It allows someone to query both the alias name and the original name. Do you think that's important? (I assume so, since you've been giving it a lot of thought and opted for this).
There was a problem hiding this comment.
hey, I think it can be removed, I mean inlined in evented_setattr, as it is only used there. And SignalGroup has one less method.
There was a problem hiding this comment.
i do think that end-users should also be able to search by alias. but i guess the question is should they no longer be able to search by the original name? i.e. if I remove the method on SignalGroup, then end-users can no longer access the original names for an aliased signal, correct? are we ok with that?
There was a problem hiding this comment.
I made a function instead of a method, with a new name get_signal_from_field.
|
I see you had to do something quite convoluted to avoid the performance regression. But I'm glad you managed to make it work. I can commit the change I have in mind for the benchmark workflow to run if you want. |
I agree! go for it
the codspeed benchmarks actually can't be run in local, (only the asv ones, and this wasn't a regression in those benchmarks)... so i just guessed it would help and got lucky :)
sure! |
|
They can always use `group._psygnal_aliases` if they want. But I'm thinking now that it's probably useful to have an easy and user-friendly way to get the signal alias for a given field.
Maybe we can have `get_signal_by_alias` be a function (that takes a `SignalGroup` as first arg) instead of a method?
…On 21 March 2024 13:40:05 GMT+00:00, Talley Lambert ***@***.***> wrote:
@tlambert03 commented on this pull request.
> + def get_signal_by_alias(self, name: str) -> SignalInstance | None:
+ sig_name = self._psygnal_aliases.get(name, name)
+ if sig_name is None or sig_name not in self:
+ return None
+ return self[sig_name]
i do think that end-users should also be able to search by alias. but i guess the question is should they no longer be able to search by the original name? i.e. if I remove the method on SignalGroup, then end-users can no longer access the original names for an aliased signal, correct? are we ok with that?
--
Reply to this email directly or view it on GitHub:
#299 (comment)
You are receiving this because you were mentioned.
Message ID: ***@***.***>
|
Nope... |
|
thanks @getzze. I'm still conflicted on how to present the fetching of signals by alias publicly. I don't like a top-level |
|
It sounds good, thanks! |
Split from #265
solves #261
Add a keyword argument to
SignalGroupDescriptorto specify signal aliases (if the alias is None, no signal is created for this field). The signal aliases table is stored in theSignalGroupclass (or subclass).