Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyInquirer\prompts\input.py", line 20 TypeError: issubclass() arg 1 must be a class #19

Closed
vc1 opened this issue Oct 16, 2018 · 5 comments

Comments

@vc1
Copy link

vc1 commented Oct 16, 2018

Traceback (most recent call last):
  File "main.py", line 8, in <module>
    answers = choice()
  File "C:\Users\x\choice.py", line 85, in choice
    answers = Dict(prompt(questions, style=style))
  File "D:\Program Files\Python37\lib\site-packages\PyInquirer\prompt.py", line 63, in prompt
    application = getattr(prompts, type).question(message, **_kwargs)
  File "D:\Program Files\Python37\lib\site-packages\PyInquirer\prompts\input.py", line 20, in question
    if issubclass(validate_prompt, Validator):
  File "D:\Program Files\Python37\lib\abc.py", line 143, in __subclasscheck__
    return _abc_subclasscheck(cls, subclass)
TypeError: issubclass() arg 1 must be a class
@vc1
Copy link
Author

vc1 commented Oct 16, 2018

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

@vc1 vc1 changed the title no support for python37 PyInquirer\prompts\input.py", line 20 TypeError: issubclass() arg 1 must be a class Oct 17, 2018
@CITGuru
Copy link
Owner

CITGuru commented Oct 23, 2018

Hello @vc1, sorry for late reply and thanks for pointing this out. Can you make this a PR instead?

@davidlj95
Copy link
Contributor

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

@CITGuru
Copy link
Owner

CITGuru commented Nov 22, 2018

The issue has been fixed and the fix is merged

@CITGuru CITGuru closed this as completed Nov 22, 2018
@Psycoguana
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants