Skip to content

Commit

Permalink
Use empty string as null value for FileEdit (#384)
Browse files Browse the repository at this point in the history
* make fileedit use empty string as null value

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix typing, maybe?

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
brisvag and pre-commit-ci[bot] committed Mar 17, 2022
1 parent 0fa849a commit 9c65b23
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
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

0 comments on commit 9c65b23

Please sign in to comment.