I'm trying to use the profiler in the Python 2.1 RPM on
Red Hat 7.0.
Here's the most reduced form of problem I could come up
with. This is the file ProfilerBug.py:
from __future__ import nested_scopes
class Spam:
def __init__(self, x, y, z):
eggs = (self, x, y, z)
a = 4
b = 5
c = 6
def f(t):
return a + b + c + t
def _test1():
pr = Spam(1, 2, 3)
If I do this:
Python 2.1 (#1, Jul 13 2001, 10:27:46)
[GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-85)] on linux2
Type "copyright", "credits" or "license" for more
information.
>>> import ProfilerBug
>>> ProfilerBug._test1()
>>>
there's no error. But here's what I get when I run the
profiler:
Python 2.1 (#1, Jul 13 2001, 10:27:46)
[GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-85)] on linux2
Type "copyright", "credits" or "license" for more
information.
>>> import profile
>>> import ProfilerBug
>>> profile.run('ProfilerBug._test1()')
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.1/profile.py", line 71, in run
prof = prof.run(statement)
File "/usr/lib/python2.1/profile.py", line 356, in run
return self.runctx(cmd, dict, dict)
File "/usr/lib/python2.1/profile.py", line 362, in runctx
exec cmd in globals, locals
File "<string>", line 1, in ?
File "ProfilerBug.py", line 15, in _test1
pr = Spam(1, 2, 3)
File "ProfilerBug.py", line 6, in __init__
eggs = (self, x, y, z)
UnboundLocalError: local variable 'self' referenced
before assignment
It has something to do with nested scopes, because if I
comment out the definition of f, the error goes away.
|