Accept a boolean or a list of acceptable values I want to be able to accept True/False or a list of acceptable exit statuses for a command. This way I can choose whether to check and default to checking exit status 0 unless a list of exit statuses is provided to check against. My first instinct is to do a double reassignment.

def raw(self, ssh_command, check=False):
    # removed ssh calls and processing
    check = [] if not check else check
    check = [0] if check is True else check
    # c.call_result.status -&gt; &lt;encapsulation object&gt;.&lt;named tuple&gt;.&lt;exit status&gt;
    if c.call_result.status not in check:
        raise RuntimeError("Exit status of command {} was {}.".format(ssh_command, c.call_result.status))
    return c.call_result


Is this design simply non-pythonic. Should I refactor to not accept booleans and change check=None to the function with check = [] if check is None?

def raw(self, ssh_command, statuses=None):
    # removed ssh calls and processing
    # This won't work because we'll check against an empty list always even when None is passed.
    statuses = [] if statuses is None else statuses
    if c.call_result.status not in statuses:
        raise RuntimeError("Exit status of command {} was {}.".format(ssh_command, c.call_result.status))
    return c.call_result


EDIT:
Here are what I intended the above to be in order

Accepting booleans or list of exit statuses to accept:

def raw(self, ssh_command, check=False):
    # removed ssh calls and processing which instantiate object c
    check = [0] if check is True else check
    if check and c.call_result.status not in check:
        raise RuntimeError("Exit status of command {} was {}.".format(ssh_command, c.call_result.status))


Not accepting booleans only list of statuses to accept (changed param as this is backwards incompatible):

def raw(self, ssh_command, statuses=None):
    # removed ssh calls and processing which instantiate object c
    if statuses and c.call_result.status not in check:
        raise RuntimeError("Exit status of command {} was {}.".format(ssh_command, c.call_result.status))
    return c.call_result
Of the two I'd go with the second, it doesn't make too much sense to use Booleans and Lists, but Lists and None makes more sense type wise.

The un-Pythonic part of this code, is you assign to check_values twice, which confused me a bit as I thought you were changing check.

I'd also recommend that you try to move away from global variables, c. But otherwise your code is good, :)



If you want to shorten your code a little bit, in the second version you can use or rather than a turnery, this is something that I've noticed to be somewhat popular in JavaScript, but I'm not too sure on how Python folk think of it.

def _raw(self, ssh_command, statuses=None):
    if c.call_result.status not in (statuses or []):
        raise RuntimeError("Exit status of command {} was {}.".format(ssh_command, c.call_result.status))
    return c.call_result