Skip to content

Commit 762e639

Browse files
Allow keeping bool return values
PyMI contains a workaround to avoid returning boolean values for void MI functions, mostly in an attempt to remain compatible with other WMI libraries. The problem is that we're losing boolean return values. We could just drop the workaround and let PyMI return boolean values even for void functions, however that might break some applications. Instead, we'll add an optional argument called "keep_bool_ret_vals", which can explicitly request the boolean return values to be preserved.
1 parent c6a9502 commit 762e639

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

wmi/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,7 @@ def invoke_method(self, target, method_name, *args, **kwargs):
681681
params = self._get_method_params(target, method_name)
682682
operation_options = self._get_mi_operation_options(
683683
operation_options=kwargs.pop('operation_options', None))
684+
keep_bool_ret_vals = kwargs.pop('keep_bool_ret_vals', False)
684685

685686
for i, v in enumerate(args):
686687
_, el_type, _ = params.get_element(i)
@@ -710,7 +711,8 @@ def invoke_method(self, target, method_name, *args, **kwargs):
710711
# returns void, as there's no direct way to determine it.
711712
# This won't work if the method is expected to return a
712713
# boolean value!!
713-
if element != ('ReturnValue', mi.MI_BOOLEAN, True):
714+
if (element != ('ReturnValue', mi.MI_BOOLEAN, True)
715+
or keep_bool_ret_vals):
714716
l.append(self._wrap_element(*element))
715717
return tuple(l)
716718

0 commit comments

Comments
 (0)