@@ -32,6 +32,9 @@ class RlType(Enum):
32
32
# Tells if the terminal we are running in supports vt100 control characters
33
33
vt100_support = False
34
34
35
+ # Explanation for why readline wasn't loaded
36
+ _rl_warn_reason = ''
37
+
35
38
# The order of this check matters since importing pyreadline will also show readline in the modules list
36
39
if 'pyreadline' in sys .modules :
37
40
rl_type = RlType .PYREADLINE
@@ -113,15 +116,26 @@ def pyreadline_remove_history_item(pos: int) -> None:
113
116
elif 'gnureadline' in sys .modules or 'readline' in sys .modules :
114
117
# We don't support libedit
115
118
if 'libedit' not in readline .__doc__ :
116
- rl_type = RlType .GNU
117
-
118
- # Load the readline lib so we can access members of it
119
- import ctypes
120
- readline_lib = ctypes .CDLL (readline .__file__ )
121
-
122
- # Check if we are running in a terminal
123
- if sys .stdout .isatty ():
124
- vt100_support = True
119
+ try :
120
+ # Load the readline lib so we can access members of it
121
+ import ctypes
122
+ readline_lib = ctypes .CDLL (readline .__file__ )
123
+ except AttributeError : # pragma: no cover
124
+ _rl_warn_reason = ("this application is running in a non-standard Python environment in\n "
125
+ "which readline is not loaded dynamically from a shared library file." )
126
+ else :
127
+ rl_type = RlType .GNU
128
+ vt100_support = sys .stdout .isatty ()
129
+
130
+ # Check if readline was loaded
131
+ if rl_type == RlType .NONE : # pragma: no cover
132
+ if not _rl_warn_reason :
133
+ _rl_warn_reason = ("no supported version of readline was found. To resolve this, install\n "
134
+ "pyreadline on Windows or gnureadline on Mac." )
135
+ rl_warning = ("Readline features including tab completion have been disabled because\n "
136
+ + _rl_warn_reason + '\n \n ' )
137
+ else :
138
+ rl_warning = ''
125
139
126
140
127
141
# noinspection PyProtectedMember,PyUnresolvedReferences
0 commit comments