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

Python-3.13.0b1 changes behavior on exec() versus Python-3.12 and before ... is it normal ? #118938

Closed
stonebig opened this issue May 11, 2024 · 6 comments
Labels
3.13 bugs and security fixes 3.14 new features, bugs and security fixes type-bug An unexpected behavior, bug, or error

Comments

@stonebig
Copy link

stonebig commented May 11, 2024

Bug report

Bug description:

this code works on Python-3.12 and gives

Hello, a World !
Hello, b World !

on Python-3.13.0b1 it fails on the b part:

Hello, a World !
Traceback (most recent call last):
  File "C:/..../python-3.13.0b1.amd64/Lib/site-packages/sqlite_bro/testb.py", line 16, in <module>
    test()
  File "C:/.../python-3.13.0b1.amd64/Lib/site-packages/sqlite_bro/testb.py", line 14, in test
    be=eval('py_hellob');
  File "<string>", line 1, in <module>
    __import__('idlelib.run').run.main(True)
NameError: name 'py_hellob' is not defined. Did you mean: 'py_helloa'?
a="""def py_helloa():
    "hello world"
    return ("Hello, a World !");""";

exec(a, globals(), locals());
ae=eval('py_helloa');
print(ae())

def test():
    b="""def py_hellob():
    "hello world"
    return ("Hello, b World !");""";
    exec(b, globals(), locals());
    be=eval('py_hellob');
    print(be())
test()

CPython versions tested on:

3.12, 3.13

Operating systems tested on:

Windows

@stonebig stonebig added the type-bug An unexpected behavior, bug, or error label May 11, 2024
@hugovk hugovk added 3.13 bugs and security fixes 3.14 new features, bugs and security fixes labels May 11, 2024
@hugovk
Copy link
Member

hugovk commented May 11, 2024

Thanks for testing the beta!

Perhaps related to #118888?

@terryjreedy
Copy link
Member

I am rather sure this is a duplicate.
@gaogaotiantian

@terryjreedy terryjreedy closed this as not planned Won't fix, can't repro, duplicate, stale May 11, 2024
@stonebig
Copy link
Author

stonebig commented May 11, 2024

I had read PEP 667, looks logically nice until that effect, but how to rewrite my code ?`

ha, this way:

d={}

a="""def py_helloa():
    "hello world"
    return ("Hello, a World !");""";

exec(a, globals(), locals());
ae=eval('py_helloa');
print(ae())

def test():
    b="""def py_hellob():
    "hello world"
    return ("Hello, b World !");""";
    exec(b, globals(), d);
    be=eval('py_hellob', d);
    print(be())
test()

@stonebig
Copy link
Author

seems to work in Python-3.12 too...

@stonebig
Copy link
Author

so I did a fix to work on Python-3.13.0b1 for my package, but it's not clear if I should have done it now, with #118921

@terryjreedy
Copy link
Member

Further discussion should be on the original issue #118888.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes 3.14 new features, bugs and security fixes type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants