[PyKDE] Minor bug in ModuleParser.py handling of nested scopes with self. references...

Mike C. Fletcher mcfletch at rogers.com
Fri Sep 17 03:32:59 BST 2004


This rather common Twisted idiom causes the "Application diagram" plugin 
to choke on line 328 of ModuleParser:

class Test(object):
    def connect(self ):
        """Connect to the remote host, returns deferred returning 
protocol"""
        df = ncrprotocol.connectTCP( self.host, self.port )
        def setProtocol(result):
            self.protocol= result
            return result
        df.addCallback( setProtocol )
        df.addCallback( self.authorizeProtocol )
        return df

To reproduce, save given code in a file, add to a new project and select 
Project|Diagrams|Application Diagram .

Haven't spelunked too deeply in the code, looks like the "Method" 
group-handler needs to look to see if it's defining a nested function 
within a class' method to decide which class to use.  Alternately, in 
the Attribute handler, search up the class-definition hierarchy looking 
for the nearest class.  You should also guard against potential failures 
where self. is used in functions which aren't defined within a class 
(i.e. they are mixed into a class later):

def another( self ):
    self.x = 3

will cause the same problems for with the Application diagram as the 
previous example.

________________________________________________
  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://www.vrplumber.com
  http://blog.vrplumber.com




More information about the PyQt mailing list