[Python-bugs-list] [ python-Bugs-607092 ] wrong SET_LINENO w/ multi-line func args

noreply@sourceforge.net noreply@sourceforge.net
Wed, 11 Sep 2002 02:17:15 -0700


Bugs item #607092, was opened at 2002-09-10 02:18
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=607092&group_id=5470

Category: Parser/Compiler
Group: Python 2.2.1
Status: Open
Resolution: None
Priority: 5
Submitted By: Inyeol Lee (inyeol)
>Assigned to: Nobody/Anonymous (nobody)
Summary: wrong SET_LINENO w/ multi-line func args

Initial Comment:
Python 2.2.1 (#1, Apr 10 2002, 18:25:16) 
[GCC 2.95.3 20010315 (release)] on sunos5
Type "help", "copyright", "credits" or "license" for
more information.
>>> import dis
>>> def f():  # line 1
...   a = [1, # line 2
...     2]
...   b = (1, # line 4
...     2)
...   c(1,    # line 6
...     2)
... 
>>> dis.dis(f)
          0 SET_LINENO               1

          3 SET_LINENO               2
          6 LOAD_CONST               1 (1)
          9 LOAD_CONST               2 (2)
         12 BUILD_LIST               2
         15 STORE_FAST               0 (a)

         18 SET_LINENO               4
         21 LOAD_CONST               1 (1)
         24 LOAD_CONST               2 (2)
         27 BUILD_TUPLE              2
         30 STORE_FAST               1 (b)

         33 SET_LINENO               6
         36 LOAD_GLOBAL              2 (c)
         39 LOAD_CONST               1 (1)

         42 SET_LINENO               7              
<-- Error, should not be here.
         45 LOAD_CONST               2 (2)
         48 CALL_FUNCTION            2
         51 POP_TOP             
         52 LOAD_CONST               0 (None)
         55 RETURN_VALUE        
>>> 

python 2.2.1 generates errornous SET_LINENO instruction
when
function arguments tuple is separated by physical, not
logical newline.
This results in errornous frame.f_lineno.

-Inyeol Lee


----------------------------------------------------------------------

>Comment By: Michael Hudson (mwh)
Date: 2002-09-11 09:17

Message:
Logged In: YES 
user_id=6656

Hrmm.  I find it hard to grant this the status of "bug". 
Python behaves in a way that's mildly unhelpful for a tool
you want to build.

If it was up to me, I'd say that it was the code generation
for lists, tuples, etc that was at fault.

(You should also check out current CVS, seeing as there are
no SET_LINENO instructions any more)

What I'm working up to saying is that *I'm* not going to
work on fixing this.  Someone else might, or you can come up
with a patch and I'll review it.

----------------------------------------------------------------------

Comment By: Inyeol Lee (inyeol)
Date: 2002-09-10 18:00

Message:
Logged In: YES 
user_id=595280

I'm making a debugging util which parses current source
line to get argument names. For easy parsing I need the 
starting lineno of current statement (line 1 in your example),
not the phyical lineno of current instruction (line 2). I tested
several multi-line statements with (),{},[],quotes, ... and
they all sets f_lineno as their first line, which the statement
starts, and do not reset/update f_lineno with following
physical line break. The only (as far as I tested ;-) exception
is this fucntion args tuple. For example;

a = """ # line 1
  foo
  """; b = [f(),
  g()]

Above statement sets f_lineno to 1 and use it thruout the
whole statement even though the actual call to f and g
occurs at line 3 and 4.

Even withe function args tuple, it is strange.
f(  #line1
a,b)
generates one 'SET_LINENO 1' and doesn't update it, but
f(a,  #line1
b)
generates both 'SET_LINENO 1', 'SET_LINENO 2', and 
changes f_lineno with the soft newline. I hope it fixed.
Otherwise, I should scan both ways from current f_lineno
to get a statement.

-Inyeol Lee

----------------------------------------------------------------------

Comment By: Michael Hudson (mwh)
Date: 2002-09-10 13:07

Message:
Logged In: YES 
user_id=6656

Why is this a problem?

Execution isn't really on line 6 there.  Think about code like:

f()(1,  # line 1
 c())   # line 2

when "c()" is being evaluated, surely frame.f_lineno should
be 2?  do you think it should go back to 1 when the function
f() returns is called?

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=607092&group_id=5470