def to_py_name(cpp_name, entry_type):
    """Returns the name the function should have in the Python api, based
    on the c++-function name.

    For entry_type 'function', the cpp_name is used unmodified,
    otherwise strip everything before the first underscore, so that
    e.g:
      > someclass_some_method(PyObject* self, ...)

    gets the name "some_method", and is invoked with:

      > some_object.some_method(...)

    """
    if entry_type == 'function':
        return cpp_name
    first_underscore = cpp_name.find('_')
    assert(first_underscore != -1)
    return cpp_name[first_underscore + 1:]