-
Notifications
You must be signed in to change notification settings - Fork 53
Nested containers #704
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
base: main
Are you sure you want to change the base?
Nested containers #704
Conversation
updates: - [github.com/crate-ci/typos: v1.29.9 → v1.30.0](crate-ci/typos@v1.29.9...v1.30.0) - [github.com/astral-sh/ruff-pre-commit: v0.9.7 → v0.9.9](astral-sh/ruff-pre-commit@v0.9.7...v0.9.9)
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #704 +/- ##
==========================================
- Coverage 89.28% 89.13% -0.16%
==========================================
Files 40 40
Lines 4816 4841 +25
==========================================
+ Hits 4300 4315 +15
- Misses 516 526 +10 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
hey @ndxmrb
so sorry for the long delay. couple concerns about typing and error catching. we don't need to belabor them too much, if you can fix great, otherwise let me know.
def create_widget(self, value: T | _Undefined = Undefined) -> BaseValueWidget[T]: | ||
def create_widget( | ||
self, value: T | _Undefined = Undefined | ||
) -> BaseValueWidget[T] | NestedValueWidgets: |
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 would prefer to avoid functions that return unions if at all possible. Isn't a NestedValueWidget
ultimately also just a ValueWidget
? Doesn't it have teh same interface? Is there anything in the PR here that actually requires a new type? Can we revert these NestedValueWidget changes without mypy breaking?
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 created that just to make mypy happy. But I agree not having unions is better.
Looking at QuantityEdit
for pint.Quantity
- which is a ValueWidget
, yes it should be a ValueWidget
, too. On the other hand we now have ValuedContainerWidget
e.g. for tuples, so maybe it should rather be that?
src/magicgui/schema/_ui_field.py
Outdated
cls, kwargs = get_widget_class( | ||
value=value, annotation=self.type, options=opts | ||
) | ||
except ValueError: |
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 think this except ValueError
is something I did elsewhere at one point (right?) but I don't really like it since it's rather indirect. Unless we're certain that ValueError and TypeErrors are only ever raised for the specific cases that we are catching here, I'd prefer to do some look-before-you-leap pattern instead. (At the very least, I'd like to ensure that self.type
is a valid dataclass-like object before calling build_widget on it).
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.
Yes, I just got that from here. I had to modify asdict()
as well, it didn't run out-of-the-box when using the values.
I'm now checking for dataclass-likeness. Could you elaborate how I can make sure that it's valid?
Hi @tlambert03,
restarting my work from #669 after the
ValuedContainer
changes.Still, some things are missing:
ValueWidget
s andContainerWidget
s. Does this belong totest_pydantic()
intest_ui_field.py
?Tried my best with the types again, hope it's okay that way.
Thanks for having a look!