@@ -134,14 +134,13 @@ def __subclasshook__(cls, C):
134134 pass
135135
136136
137- # Tells what implementation of readline we are using
137+ # Check what implementation of readline we are using
138138class RlType (Enum ):
139139 GNU = 1
140140 PYREADLINE = 2
141141 NONE = 3
142142
143143
144- # Check what implementation of readline we are using
145144rl_type = RlType .NONE
146145
147146if 'pyreadline' in sys .modules :
@@ -151,24 +150,16 @@ class RlType(Enum):
151150 # noinspection PyProtectedMember
152151 orig_pyreadline_display = readline .rl .mode ._display_completions
153152
154- else :
155- readline_lib_path = ''
156-
157- if 'gnureadline' in sys .modules :
158- readline_lib_path = sys .modules ['gnureadline' ].__dict__ ['__file__' ]
159- elif 'readline' in sys .modules :
160- readline_lib_path = sys .modules ['readline' ].__dict__ ['__file__' ]
153+ elif 'gnureadline' in sys .modules or 'readline' in sys .modules :
154+ rl_type = RlType .GNU
161155
162156 # Load the readline lib so we can make changes to it
163- if readline_lib_path :
164- rl_type = RlType .GNU
165-
166- import ctypes
167- readline_lib = ctypes .CDLL (readline_lib_path )
157+ import ctypes
158+ readline_lib = ctypes .CDLL (readline .__file__ )
168159
169- # Save address that rl_basic_quote_characters is pointing to since we need to override and restore it
170- rl_basic_quote_characters = ctypes .c_char_p .in_dll (readline_lib , "rl_basic_quote_characters" )
171- orig_rl_basic_quote_characters_addr = ctypes .cast (rl_basic_quote_characters , ctypes .c_void_p ).value
160+ # Save address that rl_basic_quote_characters is pointing to since we need to override and restore it
161+ rl_basic_quote_characters = ctypes .c_char_p .in_dll (readline_lib , "rl_basic_quote_characters" )
162+ orig_rl_basic_quote_characters_addr = ctypes .cast (rl_basic_quote_characters , ctypes .c_void_p ).value
172163
173164
174165# BrokenPipeError and FileNotFoundError exist only in Python 3. Use IOError for Python 2.
0 commit comments