diff --git a/coconut/command/command.py b/coconut/command/command.py index 6c6ca5a4..6549d4c3 100644 --- a/coconut/command/command.py +++ b/coconut/command/command.py @@ -1000,7 +1000,13 @@ def run_type_checking(self, paths=(), code=None): if code is not None: logger.warn("--pyright only works on files, not code snippets or at the interpreter") if paths: - from pyright import main + try: + from pyright import main + except ImportError: + raise CoconutException( + "coconut --pyright requires Pyright", + extra="run '{python} -m pip install coconut[pyright]' to fix".format(python=sys.executable), + ) args = ["--project", config_file, "--pythonversion", self.type_checking_version] + list(paths) main(args) diff --git a/coconut/command/mypy.py b/coconut/command/mypy.py index 57366b49..bcc4f636 100644 --- a/coconut/command/mypy.py +++ b/coconut/command/mypy.py @@ -34,7 +34,7 @@ from mypy.api import run except ImportError: raise CoconutException( - "--mypy flag requires MyPy library", + "coconut --mypy requires MyPy", extra="run '{python} -m pip install coconut[mypy]' to fix".format(python=sys.executable), ) diff --git a/coconut/command/util.py b/coconut/command/util.py index ccd11d74..6198d3cf 100644 --- a/coconut/command/util.py +++ b/coconut/command/util.py @@ -510,7 +510,10 @@ def update_pyright_config(python_version=None): update_existing = os.path.exists(pyright_config_file) with univ_open(pyright_config_file, "r+" if update_existing else "w") as config_file: if update_existing: - config = readfile(config_file, in_json=True) + try: + config = readfile(config_file, in_json=True) + except ValueError: + raise CoconutException("invalid JSON syntax in " + repr(pyright_config_file)) else: config = extra_pyright_args.copy() config["extraPaths"] = [install_stubs()]