Skip to content

Commit

Permalink
Allow keeping bool return values
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
petrutlucian94 committed Nov 7, 2024
1 parent c6a9502 commit 762e639
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion wmi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,7 @@ def invoke_method(self, target, method_name, *args, **kwargs):
params = self._get_method_params(target, method_name)
operation_options = self._get_mi_operation_options(
operation_options=kwargs.pop('operation_options', None))
keep_bool_ret_vals = kwargs.pop('keep_bool_ret_vals', False)

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

Expand Down

0 comments on commit 762e639

Please sign in to comment.