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

Attention: Patch coverage is 60.00000% with 8 lines in your changes missing coverage. Please review.

Project coverage is 89.15%. Comparing base (45a54d1) to head (0b88814).

Files with missing lines Patch % Lines
src/magicgui/schema/_ui_field.py 41.66% 7 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.15%   -0.14%     
==========================================
  Files          40       40              
  Lines        4816     4831      +15     
==========================================
+ Hits         4300     4307       +7     
- Misses        516      524       +8     

☔ 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?

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

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