src/eric7/DebugClients/Python/FlexCompleter.py

branch
eric7-maintenance
changeset 10460
3b34efa2857c
parent 10417
c6011e501282
child 11047
783fc3de315e
equal deleted inserted replaced
10366:411df92e881f 10460:3b34efa2857c
75 Completer instances should be used as the completion mechanism of 75 Completer instances should be used as the completion mechanism of
76 readline via the set_completer() call: 76 readline via the set_completer() call:
77 77
78 readline.set_completer(Completer(my_namespace).complete) 78 readline.set_completer(Completer(my_namespace).complete)
79 79
80 @param namespace The namespace for the completer. 80 @param namespace namespace for the completer
81 @type dict
81 @exception TypeError raised to indicate a wrong data structure of 82 @exception TypeError raised to indicate a wrong data structure of
82 the namespace object 83 the namespace object
83 """ 84 """
84 if namespace and not isinstance(namespace, dict): 85 if namespace and not isinstance(namespace, dict):
85 raise TypeError("namespace must be a dictionary") 86 raise TypeError("namespace must be a dictionary")
98 Public method to return the next possible completion for 'text'. 99 Public method to return the next possible completion for 'text'.
99 100
100 This is called successively with state == 0, 1, 2, ... until it 101 This is called successively with state == 0, 1, 2, ... until it
101 returns None. The completion should begin with 'text'. 102 returns None. The completion should begin with 'text'.
102 103
103 @param text The text to be completed. (string) 104 @param text text to be completed
104 @param state The state of the completion. (integer) 105 @type str
105 @return The possible completions as a list of strings. 106 @param state state of the completion
107 @type int
108 @return possible completions
109 @rtype list of str
106 """ 110 """
107 if self.use_main_ns: 111 if self.use_main_ns:
108 self.namespace = __main__.__dict__ 112 self.namespace = __main__.__dict__
109 113
110 if state == 0: 114 if state == 0:
119 123
120 def _callable_postfix(self, val, word): 124 def _callable_postfix(self, val, word):
121 """ 125 """
122 Protected method to check for a callable. 126 Protected method to check for a callable.
123 127
124 @param val value to check (object) 128 @param val value to check
125 @param word word to ammend (string) 129 @type Any
126 @return ammended word (string) 130 @param word word to amend
131 @type str
132 @return amended word
133 @rtype str
127 """ 134 """
128 if callable(val): 135 if callable(val):
129 word += "(" 136 word += "("
130 return word 137 return word
131 138
132 def global_matches(self, text): 139 def global_matches(self, text):
133 """ 140 """
134 Public method to compute matches when text is a simple name. 141 Public method to compute matches when text is a simple name.
135 142
136 @param text The text to be completed. (string) 143 @param text text to be completed
137 @return A list of all keywords, built-in functions and names currently 144 @type str
138 defined in self.namespace that match. 145 @return list of all keywords, built-in functions and names currently
146 defined in self.namespace that match
147 @rtype list of str
139 """ 148 """
140 matches = [] 149 matches = []
141 seen = {"__builtins__"} 150 seen = {"__builtins__"}
142 n = len(text) 151 n = len(text)
143 for word in keyword.kwlist: 152 for word in keyword.kwlist:
173 instances, class members are are also considered.) 182 instances, class members are are also considered.)
174 183
175 <b>WARNING</b>: this can still invoke arbitrary C code, if an object 184 <b>WARNING</b>: this can still invoke arbitrary C code, if an object
176 with a __getattr__ hook is evaluated. 185 with a __getattr__ hook is evaluated.
177 186
178 @param text The text to be completed. (string) 187 @param text text to be completed
179 @return A list of all matches. 188 @type str
189 @return list of all matches
190 @rtype list of str
180 """ 191 """
181 m = re.match(r"(\w+(\.\w+)*)\.(\w*)", text) 192 m = re.match(r"(\w+(\.\w+)*)\.(\w*)", text)
182 if not m: 193 if not m:
183 return [] 194 return []
184 expr, attr = m.group(1, 3) 195 expr, attr = m.group(1, 3)
222 233
223 def get_class_members(klass): 234 def get_class_members(klass):
224 """ 235 """
225 Module function to retrieve the class members. 236 Module function to retrieve the class members.
226 237
227 @param klass The class object to be analysed. 238 @param klass class object to be analyzed
228 @return A list of all names defined in the class. 239 @type Any
240 @return list of all names defined in the class
241 @rtype list of str
229 """ 242 """
230 ret = dir(klass) 243 ret = dir(klass)
231 if hasattr(klass, "__bases__"): 244 if hasattr(klass, "__bases__"):
232 for base in klass.__bases__: 245 for base in klass.__bases__:
233 ret += get_class_members(base) 246 ret += get_class_members(base)

eric ide

mercurial