From 62c5de1c1aae52a946e22fd53eadfac75fc421e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Tue, 22 Oct 2024 11:25:54 +0200 Subject: [PATCH] Fix typing errors In the force case, the metadata could be None regardless. In that case we can just disregard any warnings --- pynitrokey/cli/nk3/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pynitrokey/cli/nk3/__init__.py b/pynitrokey/cli/nk3/__init__.py index f5a4c561..977580b8 100644 --- a/pynitrokey/cli/nk3/__init__.py +++ b/pynitrokey/cli/nk3/__init__.py @@ -194,7 +194,7 @@ def set_config(ctx: Context, key: str, value: str, force: bool, dry_run: bool) - support_hint=False, ) - if not force and not field_metadata.ty.is_valid(value): + if not force and field_metadata is not None and not field_metadata.ty.is_valid(value): raise CliException( f"Invalid config value for {field}: expected {field_metadata.ty}, got `{value}`. Unknown config values can only be set if the --force/-f flag is set. Aborting.", support_hint=False, @@ -212,20 +212,20 @@ def set_config(ctx: Context, key: str, value: str, force: bool, dry_run: bool) - "user data currently stored on the device.", file=sys.stderr, ) - elif field_metadata.destructive: + elif field_metadata is not None and field_metadata.destructive: print( "This configuration value may delete data on your device", file=sys.stderr, ) - if field_metadata.destructive: + if field_metadata is not None and field_metadata.destructive: click.confirm("Do you want to continue anyway?", abort=True) if dry_run: print("Stopping dry run.", file=sys.stderr) raise click.Abort() - if field_metadata.requires_touch_confirmation: + if field_metadata is not None and field_metadata.requires_touch_confirmation: print( "Press the touch button to confirm the configuration change.", file=sys.stderr, @@ -233,7 +233,7 @@ def set_config(ctx: Context, key: str, value: str, force: bool, dry_run: bool) - device.admin.set_config(key, value) - if field_metadata.requires_reboot: + if field_metadata is not None and field_metadata.requires_reboot: print("Rebooting device to apply config change.") device.reboot()