Skip to content

Commit

Permalink
handle mypy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
seanbreckenridge committed Mar 10, 2024
1 parent d5402f9 commit a64614a
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions autotui/prompts.py
Expand Up @@ -67,9 +67,11 @@ def create_prompt_string(
def prompt_str(for_attr: Optional[str] = None, prompt_msg: Optional[str] = None) -> str:
m: str = create_prompt_string(str, for_attr, prompt_msg)
if is_enabled(Option.CLICK_PROMPT):
return click.prompt(m, prompt_suffix="")
ret = click.prompt(m, prompt_suffix="")
if not isinstance(ret, str):
raise AutoTUIException(f"Expected string, got {ret} {type(ret)}")
return ret
else:
m: str = create_prompt_string(str, for_attr, prompt_msg)
return prompt(m)


Expand All @@ -88,7 +90,10 @@ def validate(self, document: Document) -> None:
def prompt_int(for_attr: Optional[str] = None, prompt_msg: Optional[str] = None) -> int:
m: str = create_prompt_string(int, for_attr, prompt_msg)
if is_enabled(Option.CLICK_PROMPT):
return click.prompt(m, type=int, prompt_suffix="")
ret = click.prompt(m, type=int, prompt_suffix="")
if not isinstance(ret, int):
raise AutoTUIException(f"Expected int, got {ret} {type(ret)}")
return ret
else:
return int(prompt(m, validator=IntValidator()))

Expand All @@ -110,7 +115,10 @@ def prompt_float(
) -> float:
m: str = create_prompt_string(float, for_attr, prompt_msg)
if is_enabled(Option.CLICK_PROMPT):
return click.prompt(m, type=float, prompt_suffix="")
ret = click.prompt(m, type=float, prompt_suffix="")
if not isinstance(ret, float):
raise AutoTUIException(f"Expected float, got {ret} {type(ret)}")
return ret
else:
return float(prompt(m, validator=FloatValidator()))

Expand Down Expand Up @@ -269,7 +277,8 @@ def prompt_enum(
if is_enabled(Option.CLICK_PROMPT):
# these is no autocomplete in click, warn the user to enable ENUM_FZF instead
click.echo(
"No autocompletion for enums in click. Consider enabling ENUM_FZF option", err=True
"No autocompletion for enums in click. Consider enabling ENUM_FZF option",
err=True,
)

class EnumClosureValidator(Validator):
Expand Down

0 comments on commit a64614a

Please sign in to comment.