Skip to content

Commit 945d294

Browse files
committed
Use inspect over code obj internals where possible
1 parent f1ddfe2 commit 945d294

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/problem_bank_scripts/problem_bank_scripts.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1616,10 +1616,10 @@ def pl_to_md(question: os.PathLike):
16161616
functions[func_name] = "pass\n"
16171617
if not inspect.isfunction(func):
16181618
raise ValueError(f"Could not find a callable function {func_name} in server.py for question {path.name} (found non callable object instead)")
1619-
if func.__code__.co_argcount != 1:
1620-
raise ValueError(f"Function {func_name} in server.py for question {path.name} does not have the correct number of arguments (expected 1, got {func.__code__.co_argcount})")
1621-
if func.__code__.co_varnames[0] != "data":
1622-
raise ValueError(f"Function {func_name} in server.py for question {path.name} does not have the correct argument name (expected 'data', got {func.__code__.co_varnames[0]!r})")
1619+
if len(arguments := inspect.getargs(func.__code__)) != 1 :
1620+
raise ValueError(f"Function {func_name} in server.py for question {path.name} does not have the correct number of arguments (expected 1, got {len(arguments)})")
1621+
if arguments[0] != "data":
1622+
raise ValueError(f"Function {func_name} in server.py for question {path.name} does not have the correct argument name (expected 'data', got {arguments[0]!r})")
16231623
func_code = inspect.getsource(func)
16241624
functions[func_name] = textwrap.dedent(func_code.split("\n", 1)[-1]) # remove "def name(data):"" line, and remove unnecessary indentation
16251625
end_line_no = func_code.count("\n") + func.__code__.co_firstlineno

0 commit comments

Comments
 (0)