This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mrdiskodave
Recipients mrdiskodave
Date 2009-09-16.15:38:38
SpamBayes Score 5.8609784e-12
Marked as misclassified No
Message-id <1253115523.94.0.244610185437.issue6921@psf.upfronthosting.co.za>
In-reply-to
Content
I was playing about with ideas behind b-plus-trees
and found i python bug

the important bit of code is:

            


            for p, k in enumerate(self.keys):
                self.ptrs[p].dump(indent+1, kmin=lk, kmax=k)
                print sindent + "(" + str(k) + ")"
                lk = k

            #
            # python bug?
            #
            show_python_bug = len(sys.argv)>1
            if show_python_bug:
                #
                # why not this?
                assert p == len(self.keys)-1
            else:
                #
                # why do I need this instead?
                p = len(self.keys)-1


i'm expecting k to still be in scope and equal len(self.keys)-1
sometimes it is and sometimes it isn't (depending on recursion depth)

you can try it for yourselves as I attach the full program:

./btree.py
runs fine
./btree.py  show_python_bug
eventually breaks like this:

Traceback (most recent call last):
  File "./btree.py", line 235, in <module>
    page.dump()
  File "./btree.py", line 223, in dump
    self.ptrs[p+1].dump(indent+1, kmin=lk)
  File "./btree.py", line 223, in dump
    self.ptrs[p+1].dump(indent+1, kmin=lk)
  File "./btree.py", line 223, in dump
    self.ptrs[p+1].dump(indent+1, kmin=lk)
  File "./btree.py", line 217, in dump
    assert p == len(self.keys)-1
UnboundLocalError: local variable 'p' referenced before assignment

... despite executing that code many times successfully before this
happens ... strange!

I hope you can figure it out and that this report proves helpful.
History
Date User Action Args
2009-09-16 15:38:44mrdiskodavesetrecipients: + mrdiskodave
2009-09-16 15:38:43mrdiskodavesetmessageid: <1253115523.94.0.244610185437.issue6921@psf.upfronthosting.co.za>
2009-09-16 15:38:42mrdiskodavelinkissue6921 messages
2009-09-16 15:38:40mrdiskodavecreate