Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'argument': 0.05; 'explicitly': 0.05; '"""': 0.07; 'class,': 0.07; 'debugging': 0.07; 'method.': 0.07; 'pypy': 0.07; '51,': 0.09; 'subject:instance': 0.09; 'subject:method': 0.09; 'python': 0.11; 'def': 0.12; "%s'": 0.16; '(false,': 0.16; 'add(self,': 0.16; 'complaining': 0.16; 'key):': 0.16; 'node)': 0.16; 'node.': 0.16; 'placeholder': 0.16; 'skip:" 80': 0.16; 'subclass': 0.16; 'subject: \n ': 0.16; 'to:name:python list': 0.16; 'typeerror:': 0.16; 'unbound': 0.16; '<': 0.19; 'print': 0.22; 'error': 0.23; 'adds': 0.24; 'code:': 0.26; 'skip:" 20': 0.27; 'point': 0.28; 'errors': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'getting': 0.31; '3.x': 0.31; 'node': 0.31; 'file': 0.32; 'thanks!': 0.32; '(most': 0.33; 'skip:& 30': 0.33; 'skip:b 30': 0.33; 'subject: (': 0.35; 'subject:with': 0.35; 'test': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'returning': 0.36; 'method': 0.36; 'being': 0.38; 'skip:& 10': 0.38; 'to:addr:python- list': 0.38; 'recent': 0.39; 'skip:& 20': 0.39; '\xa0\xa0\xa0': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'first': 0.61; 'different': 0.65; 'containing': 0.69; '8bit%:100': 0.72; 'is\xa0': 0.84; 'subject:nothing': 0.84; '\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0': 0.84; 'subject:add': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to :content-type; bh=cVWcdUfij19/XLful3nB54B676BS9AlUXBrhFHtiic8=; b=yQJFlUgxWXIA8pjK8xcyW281iNjtUQqqaimpMZ4CEORrImBYWcNHq4yH8jCKGKTn6t SrTPpP48xCE/oBSfsxdTaHF4E8oolFVQLSoFwN/S991kCv6P5hcuTsjPxY1ynMgVt1G0 M5mLUaEgCMHM6qAMeLcfuKXOhwkC6D9up0hdYh0jXiXs/DNgeWNMdhNnSf+bdUQpWHgL e7V7waFohUKfNT83vL5Z1dQscAAlLEvIpcZR/GWcK94/GlPiONYrvH3DdruauQ+AwbO3 I6zneGYyX41zJ5cuAaz3ts4FNHouIVInU/1tUZruin2IlTtEuBQ0ZWzmB+KSWezElAr5 8UgQ== MIME-Version: 1.0 X-Received: by 10.49.15.103 with SMTP id w7mr33489598qec.46.1368903672354; Sat, 18 May 2013 12:01:12 -0700 (PDT) Date: Sat, 18 May 2013 12:01:12 -0700 Subject: TypeError: unbound method add() must be called with BinaryTree instance as first argument (got nothing instead) From: Dan Stromberg To: Python List Content-Type: multipart/alternative; boundary=047d7bd757441f7b0a04dd02b936 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 111 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1368903676 news.xs4all.nl 15928 [2001:888:2000:d::a6]:40730 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:45522 --047d7bd757441f7b0a04dd02b936 Content-Type: text/plain; charset=ISO-8859-1 I'm getting the error in the subject, from the following code: def add(self, key): """ Adds a node containing I{key} to the subtree rooted at I{self}, returning the added node. """ node = self.find(key) if not node: node.key = key # placeholder node.left, node.right = self.__class__(parent=node), self.__class__(parent=node) return (False, node) else: if random.random() < 0.5: print('node.left is %s' % node.left) return BinaryTree.add(self=node.left, key=key) else: print('node.right is %s' % node.left) return BinaryTree.add(self=node.right, key=key) The above add() method is part of a BinaryTree(object) class, whose subclass is RedBlackTree. We need to explicitly call BinaryTree.add() with an explict self, to avoid inappropriately calling RedBlackTree.add().; BinaryTree.add() is being called with a RedBlackTree instance as self. The debugging print and traceback look like: node.left is 0 -1 red Traceback (most recent call last): File "app_main.py", line 51, in run_toplevel File "test-red_black_tree_mod", line 328, in test() File "test-red_black_tree_mod", line 316, in test all_good &= test_duplicates() File "test-red_black_tree_mod", line 194, in test_duplicates tree.add(value) File "/home/dstromberg/src/home-svn/red-black-tree-mod/trunk/duncan/red_black_bag_mod.py", line 919, in add (replaced, node) = super(RedBlackTree, self).add(key=key) File "/home/dstromberg/src/home-svn/red-black-tree-mod/trunk/duncan/red_black_bag_mod.py", line 376, in add return BinaryTree.add(self=node.left, key=key) TypeError: unbound method add() must be called with BinaryTree instance as first argument (got nothing instead) Why is it complaining that .add() is getting nothing, when node.left isn't None? As you can see above the traceback, it's got a value represented by "node.left is 0 -1 red". python 2.x, python 3.x and pypy all give this same error, though jython errors out at a different point in the same method. Thanks! --047d7bd757441f7b0a04dd02b936 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

I'm getting the error in the = subject, from the following code:
=A0=A0=A0 def add(self, key):
=A0= =A0=A0=A0=A0=A0=A0 """
=A0=A0=A0=A0=A0=A0=A0 Adds a node = containing I{key} to the subtree
=A0=A0=A0=A0=A0=A0=A0 rooted at I{self}, returning the added node.
=A0= =A0=A0=A0=A0=A0=A0 """
=A0=A0=A0=A0=A0=A0=A0 node =3D sel= f.find(key)
=A0=A0=A0=A0=A0=A0=A0 if not node:
=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0 node.key =3D key
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 # placeh= older
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 node.left, node.right =3D self._= _class__(parent=3Dnode), self.__class__(parent=3Dnode)
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 return (False, node)
=A0=A0=A0=A0=A0= =A0=A0 else:
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if random.random() < 0= .5:
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 print('node.left i= s %s' % node.left)
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ret= urn BinaryTree.add(self=3Dnode.left, key=3Dkey)
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 else:
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 print('node.right is %s' % node.left)
=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 return BinaryTree.add(self=3Dnode.righ= t, key=3Dkey)

The above add() method is part of a BinaryTree(o= bject) class, whose subclass is RedBlackTree.

We need to explicitly call BinaryTree.add() with an explict = self, to avoid inappropriately calling RedBlackTree.add().; BinaryTree.add(= ) is being called with a RedBlackTree instance as self.

The debugging print and traceback look like:
node.left is=A0 0 -1 redTraceback (most recent call last):
=A0 File "app_main.py", li= ne 51, in run_toplevel
=A0 File "test-red_black_tree_mod", lin= e 328, in <module>
=A0=A0=A0 test()
=A0 File "test-red_black_tree_mod", line 316,= in test
=A0=A0=A0 all_good &=3D test_duplicates()
=A0 File "= ;test-red_black_tree_mod", line 194, in test_duplicates
=A0=A0=A0 t= ree.add(value)
=A0 File "/home/dstromberg/src/home-svn/red-black-tr= ee-mod/trunk/duncan/red_black_bag_mod.py", line 919, in add
=A0=A0=A0 (replaced, node) =3D super(RedBlackTree, self).add(key=3Dkey)
= =A0 File "/home/dstromberg/src/home-svn/red-black-tree-mod/trunk/dunca= n/red_black_bag_mod.py", line 376, in add
=A0=A0=A0 return BinaryTr= ee.add(self=3Dnode.left, key=3Dkey)
TypeError: unbound method add() must be called with BinaryTree instance as = first argument (got nothing instead)

Why is it complainin= g that .add() is getting nothing, when node.left isn't None?=A0 As you = can see above the traceback, it's got a value represented by "node= .left is=A0 0 -1 red".

python 2.x, python 3.x and pypy all give this same error, th= ough jython errors out at a different point in the same method.

Thanks!

--047d7bd757441f7b0a04dd02b936--