from pychecker2.util import parents

from compiler import ast

class File:
    def __init__(self, name):
        self.name = name
        self.parseTree = None
        self.scopes = {}
        self.root_scope = None
        self.warnings = []

    def __cmp__(self, other):
        return cmp(self.name, other.name)

    def warning(self, line, warn, *args):
        lineno = line
	try:
	    lineno = line.lineno
        except AttributeError:
	    pass
        if not lineno:
            try:
                for p in parents(line):
                    if p.lineno:
                        lineno = p.lineno
                        break
            except AttributeError:
                pass
        self.warnings.append( (lineno, warn, args) )

    def scope_filter(self, type):
        return [(n, s)
                for n, s in self.scopes.iteritems() if isinstance(n, type)
                ]

    def function_scopes(self):
        return self.scope_filter(ast.Function)

    def class_scopes(self):
        return self.scope_filter(ast.Class)

@@ -373,94 +373,46 @@
 o = 
-line%0A%09try:%0A%09    lineno = line.lineno%0A        except AttributeError:%0A%09    pass%0A
+getattr(line, 'lineno', line)%0A   
      
-   
 if n
@@ -424,25 +424,36 @@
 neno
-:%0A            try
+ and hasattr(line, 'parent')
 :%0A  
@@ -458,28 +458,24 @@
             
-    
 for p in par
@@ -502,20 +502,16 @@
         
-   
- 
 if p.lin
@@ -515,20 +515,16 @@
 lineno:%0A
-    
         
@@ -577,74 +577,14 @@
     
-  
-  
 break%0A
-            except AttributeError:%0A                pass%0A
     
@@ -687,39 +687,15 @@
 rn %5B
-(n, s)%0A               
+x
  for 
-n, s
+x
  in 
@@ -736,33 +736,19 @@
 nce(
-n
+x%5B0%5D
 , type)
-%0A                
 %5D%0A%0A 
@@ -897,8 +897,213 @@
 .Class)%0A
+%0A    def not_class_scopes(self):%0A        result = %5B%5D%0A        for n, s in self.scopes.iteritems():%0A            if not isinstance(n, ast.Class):%0A                result.append( (n, s) )%0A        return result%0A

simplify lineno code add utility to get all scopes, except class scopes