Skip to content

Commit

Permalink
io.selective_input: replaced ellipsises with None
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramin-RX7 committed Jul 13, 2023
1 parent ba2ab74 commit d177a94
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions rx7/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ def wait_for_input(prompt="") -> str:
return answer


def selective_input(prompt:Any, choices:Iterable|Callable[[str],bool], default:Any=...,
def selective_input(prompt:Any, choices:Iterable|Callable[[str],bool], default:Any=None,
*,
ignore_case:bool=False, invalid_message:Any='Invalid input',
pre_action:Callable=...,post_action:Callable=...) -> str|Any:
pre_action:Callable=None,post_action:Callable=None) -> str|Any:
"""Prompts for user input and waits until a acceptable input is given
Args:
Expand All @@ -50,8 +50,8 @@ def selective_input(prompt:Any, choices:Iterable|Callable[[str],bool], default:A
Returns:
str|Any: user input as a string unless pre_action/post_action change the string type
"""
assert (callable(pre_action ) or pre_action==...)
assert (callable(post_action) or post_action==...)
assert (callable(pre_action ) or pre_action ==None)
assert (callable(post_action) or post_action==None)
if not callable(choices):
Choices = choices
if type(choices) == dict:
Expand All @@ -60,7 +60,7 @@ def selective_input(prompt:Any, choices:Iterable|Callable[[str],bool], default:A
Choices = [item.lower() for item in Choices if isinstance(item,str)]
while True:
inp = input(prompt)
if pre_action != ...:
if pre_action is not None:
inp = pre_action(inp)
inp = inp.lower() if ignore_case else inp
if callable(choices):
Expand All @@ -85,7 +85,7 @@ def selective_input(prompt:Any, choices:Iterable|Callable[[str],bool], default:A
inp = choices[inp]
except KeyError:
pass
if post_action != ...:
if post_action != None:
inp = post_action(inp)
return inp

Expand Down

0 comments on commit d177a94

Please sign in to comment.