Commits

Alex Gaynor committed 5d31d8f

remove some dead imports, some PEP8, general cleanups

  • Participants
  • Parent commits e589c0e

Comments (0)

Files changed (13)

rpython/rtyper/annlowlevel.py

 The code needed to flow and annotate low-level helpers -- the ll_*() functions
 """
 
-import types
-from rpython.tool.sourcetools import valid_identifier
 from rpython.annotator import model as annmodel
 from rpython.annotator.policy import AnnotatorPolicy, Sig
 from rpython.annotator.specialize import flatten_star_args
+from rpython.flowspace.model import Constant
+from rpython.rlib.objectmodel import specialize
+from rpython.rtyper import extregistry
 from rpython.rtyper.lltypesystem import lltype
 from rpython.rtyper.ootypesystem import ootype
-from rpython.rtyper import extregistry
-from rpython.flowspace.model import Constant
+from rpython.rtyper.rmodel import warning
+from rpython.tool.sourcetools import valid_identifier
 from rpython.translator.simplify import get_functype
-from rpython.rtyper.rmodel import warning
-from rpython.rlib.objectmodel import specialize
+
 
 class KeyComp(object):
     def __init__(self, val):
             if compact is None:
                 s = repr(val)
             else:
-                s = compact()        
+                s = compact()
         return s + 'Const'
     __repr__ = __str__
 
         args_s[:] = [l2a(a2l(s)) for s in args_s]
         return LowLevelAnnotatorPolicy.default_specialize(funcdesc, args_s)
     specialize__semierased = staticmethod(specialize__semierased)
-    
+
     specialize__ll = default_specialize
 
     def specialize__ll_and_arg(funcdesc, args_s, *argindices):
 
 def annotate_lowlevel_helper(annotator, ll_function, args_s, policy=None):
     if policy is None:
-        policy= LowLevelAnnotatorPolicy()
+        policy = LowLevelAnnotatorPolicy()
     return annotator.annotate_helper(ll_function, args_s, policy)
 
 # ___________________________________________________________________
         else:
             FUNC = F.TO
             resultcls = annmodel.SomePtr
-        
+
         args_s = [annmodel.lltype_to_annotation(T) for T in FUNC.ARGS]
         key = (llhelper, s_callable.const)
         s_res = self.bookkeeper.emulate_pbc_call(key, s_callable, args_s)
         assert s.islower()
         def expand(s_self, *args_s):
             assert isinstance(s_self, annmodel.SomePtr)
-            return getattr(s_self.ll_ptrtype.TO, s.upper()) 
+            return getattr(s_self.ll_ptrtype.TO, s.upper())
     return expand
 
 def typemeth_placeholder_sigarg(s):
         def expand(s_TYPE, *args_s):
             assert isinstance(s_TYPE, annmodel.SomePBC)
             assert s_TYPE.is_constant()
-            return getattr(s_TYPE.const, s.upper()) 
+            return getattr(s_TYPE.const, s.upper())
     return expand
 
-            
+
 class ADTInterface(object):
 
     def __init__(self, base, sigtemplates):

rpython/rtyper/exceptiondata.py

-from rpython.rtyper import rclass
 from rpython.annotator import model as annmodel
 from rpython.rlib import rstackovf
+from rpython.rtyper import rclass
 
 
 # the exceptions that can be implicitely raised by some operations
         r_instance = rclass.getinstancerepr(rtyper, None)
         r_type.setup()
         r_instance.setup()
-        self.r_exception_type  = r_type
+        self.r_exception_type = r_type
         self.r_exception_value = r_instance
-        self.lltype_of_exception_type  = r_type.lowleveltype
+        self.lltype_of_exception_type = r_type.lowleveltype
         self.lltype_of_exception_value = r_instance.lowleveltype
         self.rtyper = rtyper
 
     def make_standard_exceptions(self, rtyper):
         bk = rtyper.annotator.bookkeeper
         for cls in self.standardexceptions:
-            classdef = bk.getuniqueclassdef(cls)
+            bk.getuniqueclassdef(cls)
 
     def finish(self, rtyper):
         bk = rtyper.annotator.bookkeeper

rpython/rtyper/llinterp.py

-from rpython.flowspace.model import FunctionGraph, Constant, Variable, c_last_exception
-from rpython.rlib.rarithmetic import intmask, r_uint, ovfcheck, r_longlong, r_longlonglong
-from rpython.rlib.rarithmetic import r_ulonglong, is_valid_int
-from rpython.rtyper.lltypesystem import lltype, llmemory, lloperation, llheap
-from rpython.rtyper.lltypesystem import rclass
+import cStringIO
+import os
+import sys
+import traceback
+
+import py
+
+from rpython.flowspace.model import (FunctionGraph, Constant, Variable,
+    c_last_exception)
+from rpython.rlib import rstackovf
+from rpython.rlib.objectmodel import (ComputedIntSymbolic, CDefinedIntSymbolic,
+    Symbolic)
+# intmask is used in an exec'd code block
+from rpython.rlib.rarithmetic import ovfcheck, is_valid_int, intmask
+from rpython.rtyper.lltypesystem import lltype, llmemory, lloperation, llheap, rclass
 from rpython.rtyper.ootypesystem import ootype
-from rpython.rlib.objectmodel import ComputedIntSymbolic, CDefinedIntSymbolic
-from rpython.rlib.objectmodel import Symbolic
-from rpython.rlib import rstackovf
 
-import sys, os
-import math
-import py
-import traceback, cStringIO
 
 log = py.log.Producer('llinterp')
 
     def __init__(self, *args):
         "NOT_RPYTHON"
         Exception.__init__(self, *args)
+
     def __str__(self):
         etype = self.args[0]
         #evalue = self.args[1]
         return ''.join(etype.name).rstrip('\x00')
     else:
         # ootype!
-        return etype._INSTANCE._name.split(".")[-1] 
+        return etype._INSTANCE._name.split(".")[-1]
 
 class LLInterpreter(object):
     """ low level interpreter working with concrete values. """
                     evalue = exc_data.exc_value
                     if tracer:
                         tracer.dump('raise')
-                    exc_data.exc_type  = lltype.typeOf(etype )._defl()
+                    exc_data.exc_type = lltype.typeOf(etype)._defl()
                     exc_data.exc_value = lltype.typeOf(evalue)._defl()
                     from rpython.translator import exceptiontransform
                     T = resultvar.concretetype
         if ITEMTYPE is not lltype.Void:
             array[index] = item
 
-
     def perform_call(self, f, ARGS, args):
         fobj = self.llinterpreter.typer.type_system.deref(f)
         has_callable = getattr(fobj, '_callable', None) is not None
             return self.invoke_callable_with_pyexceptions(f, *args)
         args_v = graph.getargs()
         if len(ARGS) != len(args_v):
-            raise TypeError("graph with %d args called with wrong func ptr type: %r" %(len(args_v), ARGS)) 
+            raise TypeError("graph with %d args called with wrong func ptr type: %r" %(len(args_v), ARGS))
         for T, v in zip(ARGS, args_v):
             if not lltype.isCompatibleType(T, v.concretetype):
                 raise TypeError("graph with %r args called with wrong func ptr type: %r" %
-                                (tuple([v.concretetype for v in args_v]), ARGS)) 
+                                (tuple([v.concretetype for v in args_v]), ARGS))
         frame = self.newsubframe(graph, args)
         return frame.eval()
 
         if graphs is not None:
             obj = self.llinterpreter.typer.type_system.deref(f)
             if hasattr(obj, 'graph'):
-                assert obj.graph in graphs 
+                assert obj.graph in graphs
         else:
             pass
             #log.warn("op_indirect_call with graphs=None:", f)
                 if x^y < 0 and x%%y != 0:
                     r += 1
                 return r
-                '''%locals()
+                ''' % locals()
         elif operator == '%':
             ## overflow check on % does not work with emulated int
             code = '''%(checkfn)s(x // y)
                 if x^y < 0 and x%%y != 0:
                     r -= y
                 return r
-                '''%locals()
+                ''' % locals()
         else:
-            code = 'return %(checkfn)s(x %(operator)s y)'%locals()
+            code = 'return %(checkfn)s(x %(operator)s y)' % locals()
         exec py.code.Source("""
         def %(fn)s(self, x, y):
             assert isinstance(x, %(xtype)s)
 
     _makefunc2('op_lllong_floordiv_zer',   '//', 'r_longlonglong')
     _makefunc2('op_lllong_mod_zer',        '%',  'r_longlonglong')
-    
+
     def op_int_add_nonneg_ovf(self, x, y):
         if isinstance(y, int):
             assert y >= 0
     def op_check_and_clear_exc(self):
         exc_data = self.llinterpreter.get_transformed_exc_data(self.graph)
         assert exc_data
-        etype  = exc_data.exc_type
+        etype = exc_data.exc_type
         evalue = exc_data.exc_value
-        exc_data.exc_type  = lltype.typeOf(etype )._defl()
+        exc_data.exc_type = lltype.typeOf(etype)._defl()
         exc_data.exc_value = lltype.typeOf(evalue)._defl()
         return bool(etype)
 
     def op_new(self, INST):
         assert isinstance(INST, (ootype.Instance, ootype.BuiltinType))
         return ootype.new(INST)
-        
+
     def op_oonewarray(self, ARRAY, length):
         assert isinstance(ARRAY, ootype.Array)
         assert is_valid_int(length)
         eq_name, interp_eq = \
                  wrap_callable(self.llinterpreter, eq_func, eq_obj, eq_method_name)
         EQ_FUNC = ootype.StaticMethod([DICT._KEYTYPE, DICT._KEYTYPE], ootype.Bool)
-        sm_eq = ootype.static_meth(EQ_FUNC, eq_name, _callable=interp_eq)        
+        sm_eq = ootype.static_meth(EQ_FUNC, eq_name, _callable=interp_eq)
 
         hash_name, interp_hash = \
                    wrap_callable(self.llinterpreter, hash_func, hash_obj, hash_method_name)

rpython/rtyper/raddress.py

 # rtyping of memory address operations
-from rpython.tool.pairtype import pairtype
 from rpython.annotator import model as annmodel
-from rpython.rtyper.lltypesystem.llmemory import NULL, Address, \
-     cast_adr_to_int, fakeaddress, sizeof
+from rpython.rlib.rarithmetic import r_uint
+from rpython.rtyper.lltypesystem import lltype
+from rpython.rtyper.lltypesystem.llmemory import (NULL, Address,
+    cast_adr_to_int, fakeaddress, sizeof)
 from rpython.rtyper.rmodel import Repr, IntegerRepr
 from rpython.rtyper.rptr import PtrRepr
-from rpython.rtyper.lltypesystem import lltype
-from rpython.rlib.rarithmetic import r_uint
+from rpython.tool.pairtype import pairtype
 
 
 class __extend__(annmodel.SomeAddress):
     def rtyper_makerepr(self, rtyper):
         return address_repr
-    
+
     def rtyper_makekey(self):
         return self.__class__,
 
 
     def convert_from_to((r_ptr, r_addr), v, llops):
         return llops.genop('cast_ptr_to_adr', [v], resulttype=Address)
-
-

rpython/rtyper/rbool.py

+from rpython.annotator import model as annmodel
+from rpython.rtyper.error import TyperError
+from rpython.rtyper.lltypesystem.lltype import Signed, Unsigned, Bool, Float
+from rpython.rtyper.rmodel import IntegerRepr, BoolRepr, log
 from rpython.tool.pairtype import pairtype
-from rpython.annotator import model as annmodel
-from rpython.rtyper.lltypesystem.lltype import Signed, Unsigned, Bool, Float
-from rpython.rtyper.error import TyperError
-from rpython.rtyper.rmodel import IntegerRepr, BoolRepr
-from rpython.rtyper.rmodel import log
 
 
 class __extend__(annmodel.SomeBool):
     def rtyper_makerepr(self, rtyper):
         return bool_repr
+
     def rtyper_makekey(self):
         return self.__class__,
 

rpython/rtyper/rbuilder.py

+from rpython.annotator.model import SomeChar, SomeUnicodeCodePoint
+from rpython.rlib.rstring import INIT_SIZE
+from rpython.rtyper.lltypesystem import lltype
 from rpython.rtyper.rmodel import Repr
-from rpython.rtyper.lltypesystem import lltype
-from rpython.rlib.rstring import INIT_SIZE
-from rpython.annotator.model import SomeChar, SomeUnicodeCodePoint
 
 
 class AbstractStringBuilderRepr(Repr):

rpython/rtyper/rbytearray.py

+from rpython.annotator import model as annmodel
+from rpython.rtyper.lltypesystem import lltype
+from rpython.rtyper.rmodel import IntegerRepr
+from rpython.rtyper.rstr import AbstractStringRepr
+from rpython.tool.pairtype import pairtype
 
-from rpython.annotator import model as annmodel
-from rpython.tool.pairtype import pairtype
-from rpython.rtyper.rstr import AbstractStringRepr
-from rpython.rtyper.rmodel import IntegerRepr
-from rpython.rtyper.lltypesystem import lltype
 
 class AbstractByteArrayRepr(AbstractStringRepr):
     pass

rpython/rtyper/rclass.py

 import types
-from rpython.annotator import model as annmodel
-#from rpython.annotator.classdef import isclassdef
-from rpython.annotator import description
+
+from rpython.annotator import description, model as annmodel
 from rpython.rtyper.error import TyperError
+from rpython.rtyper.lltypesystem.lltype import Void
 from rpython.rtyper.rmodel import Repr, getgcflavor, inputconst
-from rpython.rtyper.lltypesystem.lltype import Void
 
 
 class FieldListAccessor(object):
 def buildinstancerepr(rtyper, classdef, gcflavor='gc'):
     from rpython.rlib.objectmodel import UnboxedValue
     from rpython.flowspace.model import Constant
-    
+
     if classdef is None:
         unboxed = []
         virtualizable2 = False
             if self.classdef.commonbase(subclassdef) != self.classdef:
                 raise TyperError("not a subclass of %r: %r" % (
                     self.classdef.name, desc))
-        
+
         r_subclass = getclassrepr(self.rtyper, subclassdef)
         return r_subclass.getruntime(self.lowleveltype)
 
 class __extend__(annmodel.SomeInstance):
     def rtyper_makerepr(self, rtyper):
         return getinstancerepr(rtyper, self.classdef)
+
     def rtyper_makekey(self):
         return self.__class__, self.classdef
 
 class __extend__(annmodel.SomeType):
     def rtyper_makerepr(self, rtyper):
         return get_type_repr(rtyper)
+
     def rtyper_makekey(self):
         return self.__class__,
 
         s_unbound_attr = clsdef.find_attribute(meth_name).getvalue()
         s_attr = clsdef.lookup_filter(s_unbound_attr, meth_name,
                                       hop.args_s[0].flags)
-        if s_attr.is_constant():
-            xxx # does that even happen?
+        # does that even happen?
+        assert not s_attr.is_constant()
         if '__iter__' in self.allinstancefields:
             raise Exception("__iter__ on instance disallowed")
         r_method = self.rtyper.makerepr(s_attr)

rpython/rtyper/rcontrollerentry.py

+from rpython.flowspace.model import Constant
+from rpython.rtyper.error import TyperError
+from rpython.rtyper.rmodel import Repr
 from rpython.tool.pairtype import pairtype
-from rpython.flowspace.model import Constant
-from rpython.rtyper.rmodel import Repr
-from rpython.rtyper.error import TyperError
 
 
 class ControlledInstanceRepr(Repr):

rpython/rtyper/rdict.py

 from rpython.annotator import model as annmodel
+from rpython.rtyper import rmodel
 from rpython.rtyper.lltypesystem import lltype
-from rpython.rtyper import rmodel
 
 
 class __extend__(annmodel.SomeDict):
             return self.r_dict.recast_value(hop.llops, v)
         else:
             return v
-    

rpython/rtyper/rexternalobj.py

 from rpython.annotator import model as annmodel
+from rpython.rtyper import extregistry
 from rpython.rtyper.lltypesystem import lltype
-from rpython.rtyper.ootypesystem import ootype
-from rpython.rtyper.rmodel import Repr
-from rpython.rtyper import rbuiltin
-from rpython.flowspace.model import Constant, Variable
-from rpython.rtyper import extregistry
-from rpython.annotator.signature import annotation
-from rpython.tool.pairtype import pairtype
 
 # ExternalObjects
 
+
 class __extend__(annmodel.SomeExternalObject):
-
     def rtyper_makerepr(self, rtyper):
        # delegate to the get_repr() of the extregistrered Entry class
         entry = extregistry.lookup_type(self.knowntype)
         if 'const_box' in attrs:
             del attrs['const_box']
         return self.__class__, attrs
-

rpython/rtyper/rfloat.py

+from rpython.annotator import model as annmodel
+from rpython.rlib.objectmodel import _hash_float
+from rpython.rlib.rarithmetic import base_int
+from rpython.rtyper.error import TyperError
+from rpython.rtyper.lltypesystem.lltype import (Signed, Unsigned,
+    SignedLongLong, UnsignedLongLong, Bool, Float)
+from rpython.rtyper.rmodel import FloatRepr, IntegerRepr, BoolRepr, log
+from rpython.rtyper.rstr import AbstractStringRepr
 from rpython.tool.pairtype import pairtype
-from rpython.annotator import model as annmodel
-from rpython.rtyper.lltypesystem.lltype import (Signed, Unsigned, SignedLongLong,
-    UnsignedLongLong, Bool, Float)
-from rpython.rtyper.error import TyperError
-from rpython.rtyper.rmodel import FloatRepr
-from rpython.rtyper.rmodel import IntegerRepr, BoolRepr
-from rpython.rtyper.rstr import AbstractStringRepr
-from rpython.rtyper.rmodel import log
 
-from rpython.rlib.rarithmetic import base_int
-from rpython.rlib.objectmodel import _hash_float
-
-import math
 
 class __extend__(annmodel.SomeFloat):
     def rtyper_makerepr(self, rtyper):
         return float_repr
+
     def rtyper_makekey(self):
         return self.__class__,
 

rpython/rtyper/rgeneric.py

 from rpython.annotator import model as annmodel
+from rpython.rtyper.lltypesystem import lltype
 from rpython.rtyper.rmodel import Repr
-from rpython.rtyper.rpbc import AbstractFunctionsPBCRepr,\
-     AbstractMethodsPBCRepr
+from rpython.rtyper.rpbc import AbstractFunctionsPBCRepr
 from rpython.tool.pairtype import pairtype
-from rpython.rtyper.lltypesystem import lltype
+
 
 class AbstractGenericCallableRepr(Repr):
     def __init__(self, rtyper, s_generic):
         return self.call('call_args', hop)
 
     def call(self, opname, hop):
-        bk = self.rtyper.annotator.bookkeeper
         vlist = hop.inputargs(self, *self.args_r) + [hop.inputconst(lltype.Void, None)]
         hop.exception_is_here()
         v_result = hop.genop('indirect_call', vlist, resulttype=self.r_result)