-
-
Couldn't load subscription status.
- Fork 33.2k
Closed
Closed
Copy link
Labels
3.14bugs and security fixesbugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-JITtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
The following code results in two different UnboundLocalError exceptions depending on whether it's run with the JIT on or off:
def f():
if 0:
class Class:
pass
if 0:
instance = Class()
for _ in range(5000):
try:
_ = instance.f()
except Exception:
pass
Class.__bases__ = (object,)
f()With JIT on, the UnboundLocalError points to 'instance', while with JIT off it points to 'Class'.
Traceback with JIT on:
Traceback (most recent call last):
File "/home/danzin/divergences/divergence_child_6010_3_1.py", line 17, in <module>
f()
~^^
File "/home/danzin/divergences/divergence_child_6010_3_1.py", line 12, in f
_ = instance.f()
^^^^^^^^
UnboundLocalError: cannot access local variable 'instance' where it is not associated with a valueTraceback with JIT off:
Traceback (most recent call last):
File "/home/danzin/divergences/divergence_child_6010_3_1.py", line 17, in <module>
f()
~^^
File "/home/danzin/divergences/divergence_child_6010_3_1.py", line 15, in f
Class.__bases__ = (object,)
^^^^^
UnboundLocalError: cannot access local variable 'Class' where it is not associated with a valueOutput for PYTHON_LLTRACE=4:
divergence_01_lltrace.txt
Output for PYTHON_OPT_DEBUG=4:
divergence_01_opt_debug.txt
Please let me know whether you're able to reproduce this issue.
Found using lafleur.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
yihong0618 and efimov-mikhailbswck
Metadata
Metadata
Assignees
Labels
3.14bugs and security fixesbugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-JITtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error