Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify compile and eval interaction. #63489

Open
terryjreedy opened this issue Oct 18, 2013 · 2 comments
Open

Clarify compile and eval interaction. #63489

terryjreedy opened this issue Oct 18, 2013 · 2 comments
Labels
3.11 only security fixes docs Documentation in the Doc dir type-feature A feature request or enhancement

Comments

@terryjreedy
Copy link
Member

BPO 19290
Nosy @terryjreedy, @ezio-melotti

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2013-10-18.22:25:32.839>
labels = ['3.11', 'type-feature', 'docs']
title = 'Clarify compile and eval interaction.'
updated_at = <Date 2021-10-04.01:17:14.497>
user = 'https://github.com/terryjreedy'

bugs.python.org fields:

activity = <Date 2021-10-04.01:17:14.497>
actor = 'terry.reedy'
assignee = 'docs@python'
closed = False
closed_date = None
closer = None
components = ['Documentation']
creation = <Date 2013-10-18.22:25:32.839>
creator = 'terry.reedy'
dependencies = []
files = []
hgrepos = []
issue_num = 19290
keywords = []
message_count = 2.0
messages = ['200318', '202716']
nosy_count = 3.0
nosy_names = ['terry.reedy', 'ezio.melotti', 'docs@python']
pr_nums = []
priority = 'normal'
resolution = None
stage = 'needs patch'
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue19290'
versions = ['Python 3.11']

@terryjreedy
Copy link
Member Author

This issue was stimulated by bpo-17294 where there seems to be some confusion over the purpose of the compile modes with regards to return values. I then noticed that the eval doc starts wrong and later corrects itself.

I think the following sentence from the compile doc could be improved. The current version:

"The mode argument specifies what kind of code must be compiled; it can be 'exec' if source consists of a sequence of statements, 'eval' if it consists of a single expression, or 'single' if it consists of a single interactive statement (in the latter case, expression statements that evaluate to something other than None will be printed)."

My suggestion:

"The mode argument specifies the allowed source and the return value when the result is passed to eval(). It can be 'exec' for any source (a sequence of 0 to many statements); the return value will be None. It can be 'eval' if the source is a single expression; the return value will be the value of the expression. It can be 'single' if the source is a single non-empty interactive statement; the return value will be None, as with 'exec', but if the statement is an expression that evaluates to something other than None, the value will be printed."

(bpo-13677 is about changing the doc and docstring for the compile flags argument. Patches for that and this should be disjoint.)

The eval(expression, ..) doc say that expression is a string. It much later says that it can also be a code object. I think the eval doc should follow the exec doc and call the first positional-only arg 'object' and then say the same thing: 'object must be either a string or a code object.' I don't have a complete suggested revision yet.

@terryjreedy terryjreedy added the docs Documentation in the Doc dir label Oct 18, 2013
@ezio-melotti
Copy link
Member

I find your suggestion difficult to read. Maybe using a list would make it more understandable?

@ezio-melotti ezio-melotti added the type-feature A feature request or enhancement label Nov 12, 2013
@terryjreedy terryjreedy added the 3.11 only security fixes label Oct 4, 2021
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11 only security fixes docs Documentation in the Doc dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants