Google 그룹스는 더 이상 새로운 유즈넷 게시물 또는 구독을 지원하지 않습니다. 과거의 콘텐츠는 계속 볼 수 있습니다.

Can't figure out where SyntaxError: can not delete variable 'x' referenced in nested scope us coming from in python >=2.6

조회수 294회
읽지 않은 첫 메시지로 건너뛰기

Albert Hopkins

읽지 않음,
2008. 12. 9. 오후 1:11:4008. 12. 9.
받는사람 pytho...@python.org
Say I have module foo.py:

def a(x):
def b():
x
del x

If I run foo.py under Python 2.4.4 I get:

File "foo.py", line 4
del x
SyntaxError: can not delete variable 'x' referenced in nested
scope

Under Python 2.6 and Python 3.0 I get:

SyntaxError: can not delete variable 'x' referenced in nested
scope


The difference is under Python 2.4 I get a traceback with the lineno and
offending line, but I do not get a traceback in Pythons 2.6 and 3.0.

The reason why I ask is... I have a python package, 'foo', with
__init__.py and a whole bunch of other modules. It runs fine on Python
2.4 as well as 2.6, but when I run 2to3 on my foo directory and try to
'import foo' in Python 3 I get no traceback, I can't 'import foo' in
Python 2 because 'foo' is no longer Python2-compatible, but my original
Python2 version of foo imports just fine.

So is there a way to find the offending code w/o having to go through
every line of code in 'foo' by hand? I've tried using pdb but it just
breaks out of the debugger.

thanks,
-a

rdmu...@bitdance.com

읽지 않음,
2008. 12. 9. 오후 1:43:2608. 12. 9.
받는사람 pytho...@python.org
On Tue, 9 Dec 2008 at 13:11, Albert Hopkins wrote:
> Say I have module foo.py:
>
> def a(x):
> def b():
> x
> del x
[...]

> The difference is under Python 2.4 I get a traceback with the lineno and
> offending line, but I do not get a traceback in Pythons 2.6 and 3.0.

2.5 also omits the traceback. Smells like a bug to me.

--RDM

Steven D'Aprano

읽지 않음,
2008. 12. 9. 오후 5:57:3708. 12. 9.
받는사람
On Tue, 09 Dec 2008 13:11:40 -0500, Albert Hopkins wrote:

> The difference is under Python 2.4 I get a traceback with the lineno and
> offending line, but I do not get a traceback in Pythons 2.6 and 3.0.

If tracebacks are broken, surely that would be a pretty huge bug. It
seems to be broken in 2.5 as well:

>>> def a(x):
... def b():
... x
... del x
...


SyntaxError: can not delete variable 'x' referenced in nested scope

> So is there a way to find the offending code w/o having to go through


> every line of code in 'foo' by hand?

Just search for "del x" in your code. Your editor does have a search
function, surely?


--
Steven

Albert Hopkins

읽지 않음,
2008. 12. 9. 오후 10:57:3608. 12. 9.
받는사람 pytho...@python.org
On Tue, 2008-12-09 at 22:57 +0000, Steven D'Aprano wrote:
[...]

> > So is there a way to find the offending code w/o having to go
> through
> > every line of code in 'foo' by hand?
>
> Just search for "del x" in your code. Your editor does have a search
> function, surely?
>
>

Well, you'd think I'd be smart enough to think of that one, wouldn't
you? Actually, how could you since you don't know me ;-)... Anway, I
already did that and could not find the offending code.

I submitted this bug [1]. I applied the given patch but the line it
shows isn't a "del" anything so I'm even more confused.

Steven D'Aprano

읽지 않음,
2008. 12. 9. 오후 11:10:3008. 12. 9.
받는사람
On Tue, 09 Dec 2008 22:57:36 -0500, Albert Hopkins wrote:

> On Tue, 2008-12-09 at 22:57 +0000, Steven D'Aprano wrote: [...]
>> > So is there a way to find the offending code w/o having to go
>> through
>> > every line of code in 'foo' by hand?
>>
>> Just search for "del x" in your code. Your editor does have a search
>> function, surely?
>>
>>
>>
> Well, you'd think I'd be smart enough to think of that one, wouldn't
> you? Actually, how could you since you don't know me ;-)... Anway, I
> already did that and could not find the offending code.

You should have said :)


> I submitted this bug [1]. I applied the given patch but the line it
> shows isn't a "del" anything so I'm even more confused.

Ouch. You have my sympathies.

I guess you're going to have to just import each module one at a time
until you find the module that fails, then search that one.

--
Steven


새 메시지 0개