Terry J. Reedy added the comment:
Thank you Xavier. I guess the lesson is that physical line tracing works best
(and most as one would hope or expect) when physical lines are logical lines
(or compound statement header lines).
--
resolution: -> not a bug
stage: test needed -> resolve
Fred Gansevles added the comment:
Xavier, thanks! you found it.
If I look the code again, I see that with zero, one, four and five
the context-manager (i.e. Context()) and the target (one .. five) are on
the same code-line
In the case of two and three they are on a different line.
Now, with the
Xavier de Gaye added the comment:
The difference lies in the line numbers. When tracing lines, the interpreter
operates on the basis of physical lines, not logical lines
(https://docs.python.org/3/reference/lexical_analysis.html#line-structure).
The local trace function is called on the first
Fred Gansevles added the comment:
Xavier, thanks for looking at my post.
But, since all six invocations of the context manager are the same
- I did an 'ast.parse' and 'ast.dump' and the the six calls were *exactly* the
same (save lineno and col_offset) - why does 'zero', 'one', 'four' and 'five'
Xavier de Gaye added the comment:
This is an artefact that occurs as the result of raising an exception in the
local trace function.
Disassembling the first case of failure of as_context.py with the attached
script gives the following:
9 0 LOAD_GLOBAL 0 (context)
Terry J. Reedy added the comment:
ZERO <__main__.Context object at 0x00874AF3E0B8>
ONE <__main__.Context object at 0x00874AF326D8>
Traceback (most recent call last):
File "F:\Python\mypy\tem.py", line 45, in
print ('TWO', two)
NameError: name 'two' is not defined
Traceback (most re
New submission from Fred Gansevles:
I'm playing with the idea of making a DSL based on anonynous code blocks
I discovered that the behaviour of the context manager is different in some
cases if there are line-continuations in the 'with' command
I've attached a script that reproduces this behav