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

Name lookup in annotation scopes in classes does not work with non-dict globals #119821

Closed
JelleZijlstra opened this issue May 31, 2024 · 2 comments
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@JelleZijlstra
Copy link
Member

JelleZijlstra commented May 31, 2024

Bug report

Bug description:

This works:

class customdict(dict):
    def __missing__(self, key):
        return key

code = compile("type Alias = undefined", "test", "exec")
ns = customdict()
exec(code, ns)
Alias = ns["Alias"]
assert Alias.__value__ == "undefined"

But this does not:

code = compile("class A: type Alias = undefined", "test", "exec")
ns = customdict()
exec(code, ns)
Alias = ns["A"].Alias
assert Alias.__value__ == "undefined"

This is a problem for PEP 649 because we're going to rely on a non-dict globals namespace.

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

@JelleZijlstra JelleZijlstra added the type-bug An unexpected behavior, bug, or error label May 31, 2024
@JelleZijlstra JelleZijlstra self-assigned this May 31, 2024
@JelleZijlstra JelleZijlstra added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label May 31, 2024
JelleZijlstra added a commit that referenced this issue May 31, 2024
…9822)

Support non-dict globals in LOAD_FROM_DICT_OR_GLOBALS

The implementation basically copies LOAD_GLOBAL. Possibly it could be deduplicated,
but that seems like it may get hairy since the two operations have different operands.

This is important to fix in 3.14 for PEP 649, but it's a bug in earlier versions too,
and we should backport to 3.13 and 3.12 if possible.
JelleZijlstra added a commit to JelleZijlstra/cpython that referenced this issue Jun 1, 2024
python#119822)

Support non-dict globals in LOAD_FROM_DICT_OR_GLOBALS

The implementation basically copies LOAD_GLOBAL. Possibly it could be deduplicated,
but that seems like it may get hairy since the two operations have different operands.

This is important to fix in 3.14 for PEP 649, but it's a bug in earlier versions too,
and we should backport to 3.13 and 3.12 if possible.

(cherry picked from commit 80a4e38)
JelleZijlstra added a commit to JelleZijlstra/cpython that referenced this issue Jun 1, 2024
…_GLOBALS (python#119822)

Support non-dict globals in LOAD_FROM_DICT_OR_GLOBALS

The implementation basically copies LOAD_GLOBAL. Possibly it could be deduplicated,
but that seems like it may get hairy since the two operations have different operands.

This is important to fix in 3.14 for PEP 649, but it's a bug in earlier versions too,
and we should backport to 3.13 and 3.12 if possible.

(cherry picked from commit 80a4e38)
JelleZijlstra added a commit that referenced this issue Jun 1, 2024
…LS (#119822) (#119889)

dSupport non-dict globals in LOAD_FROM_DICT_OR_GLOBALS

The implementation basically copies LOAD_GLOBAL. Possibly it could be deduplicated,
but that seems like it may get hairy since the two operations have different operands.

This is important to fix in 3.14 for PEP 649, but it's a bug in earlier versions too,
and we should backport to 3.13 and 3.12 if possible.

(cherry picked from commit 80a4e38)
JelleZijlstra added a commit that referenced this issue Jun 1, 2024
…LS (#119822) (#119890)

The implementation basically copies LOAD_GLOBAL. Possibly it could be deduplicated,
but that seems like it may get hairy since the two operations have different operands.

This is important to fix in 3.14 for PEP 649, but it's a bug in earlier versions too,
and we should backport to 3.13 and 3.12 if possible.

(cherry picked from commit 80a4e38)
@encukou
Copy link
Member

encukou commented Jun 3, 2024

3.12 refleak buildbots started failing when the backport was merged.

$ ./python -m test test_type_params -R:
Using random seed: 3855735070
0:00:00 load avg: 0.70 Run 1 test sequentially
0:00:00 load avg: 0.70 [1/1] test_type_params
beginning 9 repetitions. Showing number of leaks (. for 0 or less, X for 10 or more)
12345:6789
XXXXX XXXX
test_type_params leaked [12, 12, 12, 12] references, sum=48
test_type_params leaked [8, 8, 8, 8] memory blocks, sum=32
test_type_params failed (reference leak)

== Tests result: FAILURE ==

1 test failed:
    test_type_params

Total duration: 326 ms
Total tests: run=83
Total test files: run=1/1 failed=1
Result: FAILURE

@JelleZijlstra
Copy link
Member Author

Thanks @encukou for noticing the refleak! This has been fixed now.

noahbkim pushed a commit to hudson-trading/cpython that referenced this issue Jul 11, 2024
python#119822)

Support non-dict globals in LOAD_FROM_DICT_OR_GLOBALS

The implementation basically copies LOAD_GLOBAL. Possibly it could be deduplicated,
but that seems like it may get hairy since the two operations have different operands.

This is important to fix in 3.14 for PEP 649, but it's a bug in earlier versions too,
and we should backport to 3.13 and 3.12 if possible.
estyxx pushed a commit to estyxx/cpython that referenced this issue Jul 17, 2024
python#119822)

Support non-dict globals in LOAD_FROM_DICT_OR_GLOBALS

The implementation basically copies LOAD_GLOBAL. Possibly it could be deduplicated,
but that seems like it may get hairy since the two operations have different operands.

This is important to fix in 3.14 for PEP 649, but it's a bug in earlier versions too,
and we should backport to 3.13 and 3.12 if possible.
JelleZijlstra added a commit to JelleZijlstra/cpython that referenced this issue Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants