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

unwrap exec/eval literals #486

Open
graingert opened this issue Jul 10, 2021 · 1 comment
Open

unwrap exec/eval literals #486

graingert opened this issue Jul 10, 2021 · 1 comment

Comments

@graingert
Copy link
Contributor

A common pattern in 2/3 compatible codebases is to wrap new Python 3 syntax with exec or eval with a string literal.

Examples can be seen six.reraise, various bits of twisted and tulip:

This also applies to 3.6-3.10 codebases for example positional only arguments:

if sys.version_info >= (3, 8):
    exec(
        """def fancyStuff(fn, \, ham, spam): ...
        """
    )
else:
    def fancyStuff(args, ham, spam):
        fn, *args = args
        ... 
@asottile
Copy link
Owner

I think this would be really difficult to do in the general case, but certainly possible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants