From 08977d9a081b2506eee961e753f3954744a16bf6 Mon Sep 17 00:00:00 2001 From: Lorenzo Gaifas Date: Thu, 17 Mar 2022 17:09:22 +0100 Subject: [PATCH 1/4] make fileedit use empty string as null value --- magicgui/widgets/_concrete.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/magicgui/widgets/_concrete.py b/magicgui/widgets/_concrete.py index df990dfec..e60a33ec6 100644 --- a/magicgui/widgets/_concrete.py +++ b/magicgui/widgets/_concrete.py @@ -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 @@ -503,6 +506,8 @@ def value(self) -> tuple[Path, ...] | Path | None: @value.setter def value(self, value: Sequence[PathLike] | PathLike): """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)): From bbfed32fe82e3d663073af0c3ef1a85d15388835 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 17 Mar 2022 16:13:44 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- magicgui/widgets/_concrete.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/magicgui/widgets/_concrete.py b/magicgui/widgets/_concrete.py index e60a33ec6..0f3fa0922 100644 --- a/magicgui/widgets/_concrete.py +++ b/magicgui/widgets/_concrete.py @@ -443,7 +443,7 @@ def __init__( ): value = kwargs.pop("value", None) if value is None: - value = '' + value = "" self.line_edit = LineEdit(value=value) self.choose_btn = PushButton() self.mode = mode # sets the button text too @@ -507,7 +507,7 @@ def value(self) -> tuple[Path, ...] | Path | None: def value(self, value: Sequence[PathLike] | PathLike): """Set current file path.""" if value is None and self._nullable: - value = '' + value = "" if isinstance(value, (list, tuple)): value = ", ".join(os.fspath(p) for p in value) if not isinstance(value, (str, Path)): From 9fc2e18231b4a060ab733cb04c52dc72af739ca4 Mon Sep 17 00:00:00 2001 From: Lorenzo Gaifas Date: Thu, 17 Mar 2022 17:25:27 +0100 Subject: [PATCH 3/4] fix typing, maybe? --- magicgui/_type_wrapper.py | 2 +- magicgui/widgets/_concrete.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/magicgui/_type_wrapper.py b/magicgui/_type_wrapper.py index dfbaacc71..c37ce4891 100644 --- a/magicgui/_type_wrapper.py +++ b/magicgui/_type_wrapper.py @@ -377,7 +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 = ForwardRef( annotation, is_argument=False, is_class=True ) else: diff --git a/magicgui/widgets/_concrete.py b/magicgui/widgets/_concrete.py index e60a33ec6..990451754 100644 --- a/magicgui/widgets/_concrete.py +++ b/magicgui/widgets/_concrete.py @@ -504,7 +504,7 @@ 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 = '' From c5fcf7a64e9cb4b54b3cf8121557cdc4e630922f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 17 Mar 2022 16:25:59 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- magicgui/_type_wrapper.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/magicgui/_type_wrapper.py b/magicgui/_type_wrapper.py index c37ce4891..063b6daab 100644 --- a/magicgui/_type_wrapper.py +++ b/magicgui/_type_wrapper.py @@ -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( - annotation, is_argument=False, is_class=True - ) + annotation = ForwardRef(annotation, is_argument=False, is_class=True) else: annotation = ForwardRef(annotation, is_argument=False)