CITGuru / PyInquirer

A Python module for common interactive command line user interfaces
MIT License
1.94k stars 236 forks source link

Editor example does not work #70

Open igor-egorov opened 5 years ago

igor-egorov commented 5 years ago

PyInquirer/examples/editor.py does not work :(

(newcli-dev) ➜  ~ python cli.py
Traceback (most recent call last):
  File "cli.py", line 27, in <module>
    answers = prompt(questions, style=custom_style_2)
  File "/Users/igor/PythonEnvs/newcli-dev/lib/python3.7/site-packages/PyInquirer/prompt.py", line 67, in prompt
    application = getattr(prompts, type).question(message, **_kwargs)
  File "/Users/igor/PythonEnvs/newcli-dev/lib/python3.7/site-packages/PyInquirer/prompts/editor.py", line 139, in question
    if issubclass(validate_prompt, Validator):
  File "/Users/igor/PythonEnvs/newcli-dev/bin/../lib/python3.7/abc.py", line 143, in __subclasscheck__
    return _abc_subclasscheck(cls, subclass)
TypeError: issubclass() arg 1 must be a class

Python 3.7.1 PyInquirer==1.0.3

CITGuru commented 5 years ago

Can you please share your environment details. @igor-egorov

nicola-zanardi commented 5 years ago

Same here, Python 3.7.1 64 bits on win10, clean virtualenv

CITGuru commented 5 years ago

I will check this, been off coding for two months.

ghost commented 4 years ago

I was getting the same error. You fixed the source of the error on May 28, 2019 (https://github.com/CITGuru/PyInquirer/commit/9e9efaa13b05925bb055d4aacdee55945717e930), but the latest release on PyPi is from 2018. The error goes away if I change the offending line. I ended up just git cloning the latest commit and installing it from the local folder.

halloleo commented 4 years ago

Same here. I get the error with the PyPI version of PyInquirer under Python 3.7.

jessedp commented 4 years ago

Instead of @nesadi approach, you can also just pass a Validator into the 'validate' key...

from PyInquirer import prompt, Validator, ValidationError
...
class ValidateEditor(Validator):
    def validate(self, document):
        if document.text and len(document.text.split('\n')) <= 1:
            raise ValidationError(
                message='Must be at least 1 line', cursor_position=len(document.text))
...
def askPaste():
    questions = [
        {
            'name': 'content',
            'type': 'editor',
            'message': 'Opening editor',
            # lambda text: len(text.split('\n')) >= 1 or 'Must be at least 1 line',
            'validate': ValidateEditor,
            'eargs': {
                'editor': 'default',
                'ext': '.tmp'
            },

        },
    ]
    return prompt(questions)
cachedout commented 4 years ago

@CITGuru Could we please get a new release to PyPi that includes 9e9efaa1 ? Many uses of the editor prompt are broken otherwise. Thanks!