-
Notifications
You must be signed in to change notification settings - Fork 15
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
feat: signal alias in field metadata #265
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #265 +/- ##
===========================================
- Coverage 100.00% 99.57% -0.43%
===========================================
Files 22 22
Lines 2009 2111 +102
===========================================
+ Hits 2009 2102 +93
- Misses 0 9 +9 ☔ View full report in Codecov by Sentry. |
CodSpeed Performance ReportMerging #265 will degrade performances by 24.23%Comparing Summary
Benchmarks breakdown
|
hey @getzze, thanks again for all your work on this. it's greatly appreciated. I took a quick look yesterday and I like a lot of what I see, and also have a couple minor reservations that I want to think through a bit more (such establishing any new patterns for field-specific metadata, such as the Annotated pattern for pydantic2). But in general, I think you're right: it's a very flexible solution that solves most of the issues you've pointed out so far. One other thing I'll mention is the library fieldz. I have a couple other libraries where I want to be able to support a bunch of different dataclass-like patterns, and fieldz grew out of that. I hadn't used it yet here to avoid an additional dependency, but with this PR, it might be time to consider using it's been a busy week here, so sorry that I haven't commented yet, but will have a deeper look soon. (In the meantime, don't worry too much about the mypyc compiled tests failing) |
Now it fails only with I didn't find any official way to add metadata to fields in Pydantic v2, but in the forums people seem to pass the metadata as a dict in the second argument of It would be great to add the Sorry for the large PR, it has all the part about metadata for individual fields but also the part about signal aliasing. |
src/psygnal/_group_descriptor.py
Outdated
@@ -426,13 +536,15 @@ def __get__( | |||
if instance is None: | |||
return self | |||
|
|||
signal_group = self._get_signal_group(owner) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to do this to make it work, but I think it makes sense in general so signal_group
is not recomputed for each new instance. This should not affect much performances as the call to _build_dataclass_signal_group
was cached anyway.
8db25e2
to
15c2e5d
Compare
src/psygnal/_group.py
Outdated
@@ -372,7 +381,7 @@ def signals(self) -> Mapping[str, SignalInstance]: | |||
|
|||
def __len__(self) -> int: | |||
"""Return the number of signals in the group (not including the relay).""" | |||
return len(self._psygnal_signals) | |||
return len(self._psygnal_instances) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should go to a separate PR
I rebased to About this PR, I restructured it to include 3 features:
Maybe 3 is not really needed actually. There is two ways of doing that:
The metadata part can go to another PR (or even to Another change brought by this PR is the Tell me what you think about it when you have time 🙂 |
Once #291 is merged, I'll split this PR, first add the |
sounds good! the metadata on the fields is the one i'm the most anxious about :) but we'll find something that works |
Yes, I realized mypyc was not happy about the metadatas, so it will require more work. |
adapt to SignalRelay
With #299 merged, this PR adds parsing of field metadata to define aliases directly in the fields declarations. I don't know if it's worth adding, maybe it's too much work to maintain (like keep up with the |
thanks for the update here @getzze, I do think i'm going to take you up on the offer to allow this to be low priority :) |
solves #261
supersedes #260
Add a keyword argument to
SignalGroupDescriptor
to specify signal aliases (if the alias is None, no signal is emitted when changing the field). The signal aliases table is stored in theSignalGroup
class.Also allow for specifying per-field options for Signals using the metadata of the fields (different implementation in the different packages).
It solves #261 elegantly and makes subclassing more automatic: