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

Document "exec(stmt, global_dict, local_dict)" form in Python 2? #60543

Closed
mdickinson opened this issue Oct 27, 2012 · 6 comments
Closed

Document "exec(stmt, global_dict, local_dict)" form in Python 2? #60543

mdickinson opened this issue Oct 27, 2012 · 6 comments
Assignees
Labels
docs Documentation in the Doc dir easy

Comments

@mdickinson
Copy link
Member

BPO 16339
Nosy @mdickinson
Files
  • issue16339.patch
  • issue16339_v2.patch
  • issue16339_v3.patch
  • 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 = 'https://github.com/mdickinson'
    closed_at = <Date 2012-11-25.13:28:33.952>
    created_at = <Date 2012-10-27.17:31:07.387>
    labels = ['easy', 'docs']
    title = 'Document "exec(stmt, global_dict, local_dict)" form in Python 2?'
    updated_at = <Date 2012-11-25.13:28:33.952>
    user = 'https://github.com/mdickinson'

    bugs.python.org fields:

    activity = <Date 2012-11-25.13:28:33.952>
    actor = 'mark.dickinson'
    assignee = 'mark.dickinson'
    closed = True
    closed_date = <Date 2012-11-25.13:28:33.952>
    closer = 'mark.dickinson'
    components = ['Documentation']
    creation = <Date 2012-10-27.17:31:07.387>
    creator = 'mark.dickinson'
    dependencies = []
    files = ['28106', '28108', '28109']
    hgrepos = []
    issue_num = 16339
    keywords = ['patch', 'easy']
    message_count = 6.0
    messages = ['173947', '174906', '176339', '176342', '176343', '176349']
    nosy_count = 3.0
    nosy_names = ['mark.dickinson', 'docs@python', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'patch review'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue16339'
    versions = ['Python 2.7']

    @mdickinson
    Copy link
    Member Author

    In Python 2, the 'exec' statement supports 'exec'-ing a (statement, globals, locals) tuple:

    >>> exec("print 2", {}, {})
    2

    This doesn't seem to be documented at http://docs.python.org/reference/simple_stmts.html#the-exec-statement.

    If I understand correctly, the 'exec tuple' form was originally there for backwards compatibility with ancient versions of Python; however, it now also conveniently provides the semblance of forwards compatibility with Python 3. It appears to be supported by current versions of Jython (though judging by bpo-403345 that wasn't always the case) and PyPy.

    Is this omission intentional? Is this form of exec an official, supported part of the Python 2 language?

    @mdickinson mdickinson added the docs Documentation in the Doc dir label Oct 27, 2012
    @mdickinson
    Copy link
    Member Author

    Thread on #python-dev: http://mail.python.org/pipermail/python-dev/2012-November/122543.html

    If this is documented, direct tests for this form of exec should also be added.

    @mdickinson mdickinson assigned mdickinson and unassigned docspython Nov 13, 2012
    @mdickinson
    Copy link
    Member Author

    Here's a patch for the documentation and tests.

    @mdickinson
    Copy link
    Member Author

    Updated patch: drops mention of backwards compatibility, since that's not so useful (thanks, Ezio!). Adds note about resemblance to Python 3 code.

    @mdickinson
    Copy link
    Member Author

    Rewording the sentence about Python 3.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Nov 25, 2012

    New changeset fd9c9579050d by Mark Dickinson in branch '2.7':
    Issue bpo-16339: Document and test exec(stmt, globals, locals) form in Python 2.7.
    http://hg.python.org/cpython/rev/fd9c9579050d

    @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
    docs Documentation in the Doc dir easy
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants