-
Notifications
You must be signed in to change notification settings - Fork 50
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
fix: Allow user to overwrite default widget opts #602
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -214,8 +214,8 @@ def _pick_widget_type( | |
raise_on_unknown: bool = True, | ||
) -> WidgetTuple: | ||
"""Pick the appropriate widget type for ``value`` with ``annotation``.""" | ||
annotation, _options = _split_annotated_type(annotation) | ||
options = {**_options, **(options or {})} | ||
annotation, options_ = _split_annotated_type(annotation) | ||
options = {**options_, **(options or {})} | ||
choices = options.get("choices") | ||
|
||
if is_result and annotation is inspect.Parameter.empty: | ||
|
@@ -229,9 +229,9 @@ def _pick_widget_type( | |
): | ||
return widgets.EmptyWidget, {"visible": False, **options} | ||
|
||
_type, optional = _type_optional(value, annotation) | ||
type_, optional = _type_optional(value, annotation) | ||
options.setdefault("nullable", optional) | ||
choices = choices or (isinstance(_type, EnumMeta) and _type) | ||
choices = choices or (isinstance(type_, EnumMeta) and type_) | ||
literal_choices, nullable = _literal_choices(annotation) | ||
if literal_choices is not None: | ||
choices = literal_choices | ||
|
@@ -243,7 +243,7 @@ def _pick_widget_type( | |
if widget_type == "RadioButton": | ||
widget_type = "RadioButtons" | ||
warnings.warn( | ||
f"widget_type of 'RadioButton' (with dtype {_type}) is" | ||
f"widget_type of 'RadioButton' (with dtype {type_}) is" | ||
" being coerced to 'RadioButtons' due to choices or Enum type.", | ||
stacklevel=2, | ||
) | ||
|
@@ -252,15 +252,15 @@ def _pick_widget_type( | |
|
||
# look for subclasses | ||
for registered_type in _TYPE_DEFS: | ||
if _type == registered_type or safe_issubclass(_type, registered_type): | ||
_cls, opts = _TYPE_DEFS[registered_type] | ||
return _cls, {**options, **opts} | ||
if type_ == registered_type or safe_issubclass(type_, registered_type): | ||
cls_, opts = _TYPE_DEFS[registered_type] | ||
return cls_, {**options, **opts} | ||
|
||
if is_result: | ||
_widget_type = match_return_type(_type) | ||
if _widget_type: | ||
_cls, opts = _widget_type | ||
return _cls, {**options, **opts} | ||
widget_type_ = match_return_type(type_) | ||
if widget_type_: | ||
cls_, opts = widget_type_ | ||
return cls_, {**opts, **options} | ||
# Chosen for backwards/test compatibility | ||
return widgets.LineEdit, {"gui_only": True} | ||
|
||
|
@@ -269,14 +269,14 @@ def _pick_widget_type( | |
wdg = widgets.Select if options.get("allow_multiple") else widgets.ComboBox | ||
return wdg, options | ||
|
||
_widget_type = match_type(_type, value) | ||
if _widget_type: | ||
_cls, opts = _widget_type | ||
return _cls, {**options, **opts} | ||
widget_type_ = match_type(type_, value) | ||
if widget_type_: | ||
cls_, opts = widget_type_ | ||
return cls_, {**opts, **options} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this |
||
|
||
if raise_on_unknown: | ||
raise ValueError( | ||
f"No widget found for type {_type} and annotation {annotation!r}" | ||
f"No widget found for type {type_} and annotation {annotation!r}" | ||
) | ||
|
||
options["visible"] = False | ||
|
@@ -328,7 +328,7 @@ def get_widget_class( | |
The WidgetClass, and dict that can be used for params. dict | ||
may be different than the options passed in. | ||
""" | ||
widget_type, _options = _pick_widget_type( | ||
widget_type, options_ = _pick_widget_type( | ||
value, annotation, options, is_result, raise_on_unknown | ||
) | ||
|
||
|
@@ -340,7 +340,7 @@ def get_widget_class( | |
if not safe_issubclass(widget_class, widgets.bases.Widget): | ||
assert_protocol(widget_class, WidgetProtocol) | ||
|
||
return widget_class, _options | ||
return widget_class, options_ | ||
|
||
|
||
def _import_wdg_class(class_name: str) -> WidgetClass: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
and here same change, but it is not the code branch reached by the original issue.