`vim.eval` in vim python

def get_import_path_given_word(vim: object) -> str | None:
    word = vim.eval('expand("<cword>")')

    for package, words in package_and_word.items():
        if word in words:
            import_string = f"from {package} import {word}"
            print(import_string)
            return import_string

This function above is used in vim_python.py imported into vim.

The vim.eval literally runs the string passed in as vim code and export the vim object into python object

For example, the following two vim commands are equivalent.

:py3 print(vim.eval('expand("<cword>")'))
:echom expand("<cword>")

See also :help if_pyth.txt