Skip to contents

The Python sibling of repro_defined_vars(), used by the module's report to name the file that defines a missing name (a NameError – error_type == "undefined_variable", see repro_run_scripts_py()'s classification – usually means the script expects a name another script in the same repository defines, rather than being a standalone program). Unlike R, there is no re-run in a corrected order: every Python script runs in its own python process, so a name another script defines is never available to it, whatever the order. Scans each file for top-level variable assignments (x = ..., not ==) and top-level def/class statements, so a missing name can be matched to the file that would supply it. Only a statement at the start of a (comment-free) line is taken, which approximates "top level": an assignment/def indented inside a function body or control-flow block is not a module-level name the next script would see if it only imports or runs this one, and taking it would create false ordering edges. Unlike repro_defined_vars(), there is no assign("x", ...)-style function-call form to also match – Python has no equivalent builtin that creates a module-level name by string.

Usage

.repro_py_defined_vars(code_text_list)

Arguments

code_text_list

a named list of Python code-text character vectors, one per file (names are the file_names)

Value

a data frame with file_name and a list-column defines (character vector of names each file defines at top level – variables, functions, and classes together, since a missing name can be any of the three).