Skip to content

Conversation

ndxmrb
Copy link

@ndxmrb ndxmrb commented Jun 19, 2025

Hi @tlambert03,
restarting my work from #669 after the ValuedContainer changes.

Still, some things are missing:

Tried my best with the types again, hope it's okay that way.

Thanks for having a look!

Copy link

codecov bot commented Jun 19, 2025

Codecov Report

❌ Patch coverage is 66.66667% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.13%. Comparing base (45a54d1) to head (5ab31e5).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/magicgui/schema/_ui_field.py 57.89% 8 Missing ⚠️
src/magicgui/widgets/bases/_container_widget.py 85.71% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@tlambert03 tlambert03 left a 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:
Copy link
Member

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?

Copy link
Author

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?

cls, kwargs = get_widget_class(
value=value, annotation=self.type, options=opts
)
except ValueError:
Copy link
Member

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).

Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants