Consider making PythonEditor/PythonShell importable but fail later on init
- Dominant language
- Python
- Stars
- 115
- Forks
- 54
- PR merge metrics
- No merged PRs in 30d
Description
Copied from this [comment](https://github.com/enthought/pyface/pull/796#issuecomment-725529995) and this [comment](https://github.com/enthought/pyface/pull/796#issuecomment-725532173):
> I have an alternative suggestion:
>
> do the import error check in pyface.python_shell and pyface.python_editor
if it fails, return an object which fails on instantiation with a message about needing pygments
>
> Something like:
```
from .toolkit import toolkit_object
try:
PythonEditor = toolkit_object("python_editor:PythonEditor")
except ImportError as _exception:
# Excuse pygments dependency (for Qt), otherwise re-raise
if _exception.name != "pygments":
raise
def PythonEditor(**traits):
raise RuntimeError("PythonEditor on Qt requires Pygments to be installed")
```
The tradeoff here is that deferring the failure until one attempts to instantiate the editor might cause behaviours that are harder to debug (failing early is good). On the other hand, getting an ImportError from `from pyface.api import PythonEditor` could be just as bizarre.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.