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

Deleting names referencing from enclosed and enclosing scopes #68984

Closed
ncoghlan opened this issue Aug 5, 2015 · 5 comments
Closed

Deleting names referencing from enclosed and enclosing scopes #68984

ncoghlan opened this issue Aug 5, 2015 · 5 comments
Labels
3.7 (EOL) end of life docs Documentation in the Doc dir easy

Comments

@ncoghlan
Copy link
Contributor

ncoghlan commented Aug 5, 2015

BPO 24796
Nosy @ncoghlan, @stevendaprano, @ilevkivskyi, @Mariatta
PRs
  • bpo-24796: Remove an outdated statement in execution model docs #754
  • [3.5] bpo-24796: Remove an outdated statement in execution model docs (GH-754) #774
  • [3.6] bpo-24796: Remove an outdated statement in execution model docs (GH-754) #775
  • 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 = <Date 2017-03-23.04:08:31.930>
    created_at = <Date 2015-08-05.13:05:16.963>
    labels = ['easy', '3.7', 'docs']
    title = 'Deleting names referencing from enclosed and enclosing scopes'
    updated_at = <Date 2017-03-23.04:08:31.928>
    user = 'https://github.com/ncoghlan'

    bugs.python.org fields:

    activity = <Date 2017-03-23.04:08:31.928>
    actor = 'Mariatta'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2017-03-23.04:08:31.930>
    closer = 'Mariatta'
    components = ['Documentation']
    creation = <Date 2015-08-05.13:05:16.963>
    creator = 'ncoghlan'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 24796
    keywords = ['easy']
    message_count = 5.0
    messages = ['248036', '248040', '248042', '289811', '290022']
    nosy_count = 5.0
    nosy_names = ['ncoghlan', 'steven.daprano', 'docs@python', 'levkivskyi', 'Mariatta']
    pr_nums = ['754', '774', '775']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue24796'
    versions = ['Python 3.5', 'Python 3.6', 'Python 3.7']

    @ncoghlan
    Copy link
    Contributor Author

    ncoghlan commented Aug 5, 2015

    While committing issue bpo-24129, I noticed the following in the execution model documentation:

    ==================
    If a variable is referenced in an enclosing scope, it is illegal to delete the name. An error will be reported at compile time.
    ==================

    I'm not sure what that means, as both of the following compiled fine for me under 3.4.2:

    >>> def f():
    ...     x = 1
    ...     def g():
    ...         nonlocal x
    ...         del x
    ... 
    >>> def f():
    ...     x = 1
    ...     del x
    ...     def g():
    ...         print(x)
    ...

    @ncoghlan ncoghlan added the docs Documentation in the Doc dir label Aug 5, 2015
    @ncoghlan
    Copy link
    Contributor Author

    ncoghlan commented Aug 5, 2015

    Note that I haven't attempted to resolve this myself, as I'm not sure if we should just delete the paragraph, or if we accidentally dropped a compile time error check that didn't have any tests somewhere along the line.

    Probably a good one to raise on python-dev...

    @stevendaprano
    Copy link
    Member

    I wonder if it is a left-over from the behaviour prior to 3.2? In 3.1, I
    get this syntax error:

    py> def outer():
    ... spam = 1
    ... def inner():
    ... nonlocal spam
    ... del spam
    ... inner()
    ...
    SyntaxError: can not delete variable 'spam' referenced in nested scope

    See also the "Changed in 3.2" comment here:

    https://docs.python.org/3/reference/simple_stmts.html#the-del-statement

    @ilevkivskyi
    Copy link
    Member

    It looks like it is safe to just remove this line from docs. This code

    >>> x = 1
    >>> def f():
    ...     global x
    ...     del x
    ... 
    >>> f()
    >>> x

    Works as expected, i.e. raises NameError. (The same happens for nonlocal but with UnboundLocalError.)

    @Mariatta Mariatta added easy 3.7 (EOL) end of life labels Mar 20, 2017
    @Mariatta
    Copy link
    Member

    Thanks for the PR, Ivan. Merged and backported to 3.5 and 3.6.

    @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.7 (EOL) end of life docs Documentation in the Doc dir easy
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants