What does "condition list" mean in the documentation for eval()?

To quote the documentation for eval: Built-in Functions — Python 3.9.2 documentation

eval(expression[, globals[, locals]])

The expression argument is parsed and evaluated as a Python expression (technically speaking, a condition list) using the globals and locals dictionaries as global and local namespace.

My question: What does “a condition list” mean in this context?

I tried searching for similar phrases with grep in the documentations, but this one appeared to be the only hit. I took a cursory glance at the functions implementing eval() but can’t find any reference to this concept either.

Can you help me?

(Context: I was looking at Issue 43605 and trying to see if I could help with documenting eval(). Then I found I didn’t quite understand the existing documentation.)

1 Like

It refers to the nonterminal in the Python grammar definition that the text of the expression argument must match.

There isn’t actually a nonterminal by the name of “condition list”, but I think the testlist nonterminal in the old grammar (Grammar.txt) is what was intended.

The next question is whether this nonterminal even exists in the grammer for the new PEG parser being introduced in 3.9/3.10, python.gram. I think you’d probably need to dig into the code for eval to find out exactly how the expression is parsed.

2 Likes

Hello! Thank you very much, this helps a lot.

Based on my understanding its role seems to be superseded by the rule expressively named expressions. In the relevant section of the Language Reference describing the starting symbol when parsing for eval(), the term used is expression_list.

Anyway, I think for clarity the documentation for eval() may simply replace the reference to “condition list” with a concrete link to the expression_list in the Language Reference, to the effect of

The expression argument is parsed and evaluated as a Python expression (termed “expression list” in the Language Reference) using the globals and locals dictionaries as global and local namespace.

which I feel is clearer than the current text.

1 Like

Yes, definitely an improvement.

1 Like

You could submit a documentation patch with a PR via
https://bugs.python.org/
otherwise it is unlikely that a core dev with spare time will see this
forum discussion.

Whereas if someone’s done to work to provide an obviously good small doc
tweak, it might just be accepted.

Cheers,
Cameron Simpson cs@cskk.id.au

2 Likes

Thanks. I’m working on a revision of the documentation.

1 Like