Skip to content

Commit b681130

Browse files
committed
Avoid returning object.__init__ docstring with Jython and IronPython.
`inspect.isroutine(object().__init__)` returns True with Jython and IronPython. Luckily we can easily use `inspect.isfunction(...) or inspect.ismethod(...)` instead. Fixes #13.
1 parent 6c6ba95 commit b681130

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/robotremoteserver.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,18 @@ def stop_remote_server(self):
9797
def get_keyword_names(self):
9898
get_kw_names = getattr(self._library, 'get_keyword_names', None) or \
9999
getattr(self._library, 'getKeywordNames', None)
100-
if inspect.isroutine(get_kw_names):
100+
if self._is_function_or_method(get_kw_names):
101101
names = get_kw_names()
102102
else:
103-
names = [attr for attr in dir(self._library) if attr[0] != '_'
104-
and inspect.isroutine(getattr(self._library, attr))]
103+
names = [attr for attr in dir(self._library) if attr[0] != '_' and
104+
self._is_function_or_method(getattr(self._library, attr))]
105105
return names + ['stop_remote_server']
106106

107+
def _is_function_or_method(self, item):
108+
# Cannot use inspect.isroutine because it returns True for
109+
# object().__init__ with Jython and IronPython
110+
return inspect.isfunction(item) or inspect.ismethod(item)
111+
107112
def run_keyword(self, name, args, kwargs=None):
108113
args, kwargs = self._handle_binary_args(args, kwargs or {})
109114
result = {'status': 'FAIL'}
@@ -179,9 +184,7 @@ def _get_keyword(self, name):
179184
if name == 'stop_remote_server':
180185
return self.stop_remote_server
181186
kw = getattr(self._library, name, None)
182-
if inspect.isroutine(kw):
183-
return kw
184-
return None
187+
return kw if self._is_function_or_method(kw) else None
185188

186189
def _get_error_message(self, exc_type, exc_value):
187190
if exc_type in self._fatal_exceptions:

0 commit comments

Comments
 (0)