You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
3.13: not a == b has incorrect bytecode positions #114671
Not sure if this is a bug - yes it has a different behavior. The position of an instruction is basically the source code that generates this instruction, including the arg. In 3.13, for specializing, the COMPARE_OP instruction has a new bit in the arg that indicates the result should be converted to bool, which is part of the instruction itself. In your case, that bit is set by the not before the actual comparison.
From that perspective, not actually contributes to the bytecode and should probably be included in the bytecode source (position). Of course, I'm not the expert on this topic, so @brandtbucher would have a more official explanation.
Yep. I admit it's a bit weird, but COMPARE_OP now "cares" whether or not it occurs in a boolean context, so it's natural that it would include that boolean context in its source location.
If the boolean conversion fails, the traceback should probably include the not. Since we only have one position available for both the equality and boolean conversion, I think it makes sense to make it wide enough to include both.
Activity
alexmojaki commentedon Jan 28, 2024
Here's how this affects a traceback:
gaogaotiantian commentedon Jan 28, 2024
Not sure if this is a bug - yes it has a different behavior. The position of an instruction is basically the source code that generates this instruction, including the arg. In 3.13, for specializing, the
COMPARE_OPinstruction has a new bit in the arg that indicates the result should be converted to bool, which is part of the instruction itself. In your case, that bit is set by thenotbefore the actual comparison.From that perspective,
notactually contributes to the bytecode and should probably be included in the bytecode source (position). Of course, I'm not the expert on this topic, so @brandtbucher would have a more official explanation.brandtbucher commentedon Jan 29, 2024
Yep. I admit it's a bit weird, but
COMPARE_OPnow "cares" whether or not it occurs in a boolean context, so it's natural that it would include that boolean context in its source location.If the boolean conversion fails, the traceback should probably include the
not. Since we only have one position available for both the equality and boolean conversion, I think it makes sense to make it wide enough to include both.brandtbucher commentedon Jan 29, 2024
For reference:
Tracebacks look like:
15r10nk commentedon Jan 30, 2024
Thank you for your explanation.
There is no way to make it behave like in 3.12 if I understand this correct. I think I will find a way to work around this in my code.
Good to know that it is not a bug in cpython.