Skip to content

check for deleted vars in 'raise from' (#9270) #9272

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

Merged
merged 1 commit into from
Aug 5, 2020

Conversation

aviau
Copy link
Contributor

@aviau aviau commented Aug 5, 2020

Thanks to @isra17

This fixes an issue where the following code would raise no error:

def test() -> None:
    try:
        raise Exception()
    except NotImplementedError as e:
        raise Exception("notimplemented") from e
    except Exception:
        raise Exception("test") from e

test()

e does not exist on the second except block, so we cannot raise from it. It would result in a runtime error:

UnboundLocalError: local variable 'e' referenced before assignment

See #9270 for details.

@aviau aviau force-pushed the aviau/raise-from-deleted branch from 5a1813a to 71488c6 Compare August 5, 2020 18:46
@gvanrossum gvanrossum merged commit 1bbcd53 into python:master Aug 5, 2020
@gvanrossum
Copy link
Member

Thanks for the fix, @aviau!

@aviau aviau deleted the aviau/raise-from-deleted branch August 5, 2020 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy