Skip to content
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

Use empty string as null value for FileEdit #384

Merged
merged 5 commits into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions magicgui/_type_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,7 @@ def resolve_annotation(

if isinstance(annotation, str):
if (3, 10) > sys.version_info >= (3, 9, 8) or sys.version_info >= (3, 10, 1):
annotation = ForwardRef( # type: ignore
annotation, is_argument=False, is_class=True
)
annotation = ForwardRef(annotation, is_argument=False, is_class=True)
else:
annotation = ForwardRef(annotation, is_argument=False)

Expand Down
9 changes: 7 additions & 2 deletions magicgui/widgets/_concrete.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,10 @@ def __init__(
nullable=False,
**kwargs,
):
self.line_edit = LineEdit(value=kwargs.pop("value", None))
value = kwargs.pop("value", None)
if value is None:
value = ""
self.line_edit = LineEdit(value=value)
self.choose_btn = PushButton()
self.mode = mode # sets the button text too
self.filter = filter
Expand Down Expand Up @@ -501,8 +504,10 @@ def value(self) -> tuple[Path, ...] | Path | None:
return Path(text)

@value.setter
def value(self, value: Sequence[PathLike] | PathLike):
def value(self, value: Sequence[PathLike] | PathLike | None):
"""Set current file path."""
if value is None and self._nullable:
value = ""
if isinstance(value, (list, tuple)):
value = ", ".join(os.fspath(p) for p in value)
if not isinstance(value, (str, Path)):
Expand Down