Closed vc1 closed 5 years ago
def question(message, **kwargs):
default = kwargs.pop('default', '')
validate_prompt = kwargs.pop('validate', None)
if validate_prompt:
if callable(validate_prompt):
class _InputValidator(Validator):
def validate(self, document):
verdict = validate_prompt(document.text)
if not verdict == True:
if verdict == False:
verdict = 'invalid input'
raise ValidationError(
message=verdict,
cursor_position=len(document.text))
kwargs['validator'] = _InputValidator()
elif issubclass(validate_prompt, Validator):
kwargs['validator'] = validate_prompt()
check callable first, then issubclass
Hello @vc1, sorry for late reply and thanks for pointing this out. Can you make this a PR instead?
def question(message, **kwargs): default = kwargs.pop('default', '') validate_prompt = kwargs.pop('validate', None) if validate_prompt: if callable(validate_prompt): class _InputValidator(Validator): def validate(self, document): verdict = validate_prompt(document.text) if not verdict == True: if verdict == False: verdict = 'invalid input' raise ValidationError( message=verdict, cursor_position=len(document.text)) kwargs['validator'] = _InputValidator() elif issubclass(validate_prompt, Validator): kwargs['validator'] = validate_prompt()
check callable first, then issubclass
This does not work, as the Validator
class is callable and it is not desired to enter the first if
clause
The issue has been fixed and the fix is merged
The issue has been fixed and the fix is merged
Hello, I'm having this exact same problem when trying to run the example code