[pypy-svn] pypy default: Finally remove all __slots__ and fix translation

amauryfa commits-noreply at bitbucket.org
Fri Mar 11 20:31:30 CET 2011


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: 
Changeset: r42524:3a915c30fca2
Date: 2011-03-11 20:31 +0100
http://bitbucket.org/pypy/pypy/changeset/3a915c30fca2/

Log:	Finally remove all __slots__ and fix translation

diff --git a/pypy/interpreter/astcompiler/tools/asdl_py.py b/pypy/interpreter/astcompiler/tools/asdl_py.py
--- a/pypy/interpreter/astcompiler/tools/asdl_py.py
+++ b/pypy/interpreter/astcompiler/tools/asdl_py.py
@@ -78,16 +78,15 @@
             self.emit("")
         else:
             self.emit("class %s(AST):" % (base,))
-            self.emit("")
-            slots = ", ".join(repr(attr.name.value) for attr in sum.attributes)
-            self.emit("__slots__ = (%s)" % (slots,), 1)
-            self.emit("")
             if sum.attributes:
                 args = ", ".join(attr.name.value for attr in sum.attributes)
                 self.emit("def __init__(self, %s):" % (args,), 1)
                 for attr in sum.attributes:
                     self.visit(attr)
                 self.emit("")
+            else:
+                self.emit("pass", 1)
+                self.emit("")
             for cons in sum.types:
                 self.visit(cons, base, sum.attributes)
                 self.emit("")
@@ -95,9 +94,6 @@
     def visitProduct(self, product, name):
         self.emit("class %s(AST):" % (name,))
         self.emit("")
-        slots = self.make_slots(product.fields)
-        self.emit("__slots__ = (%s)" % (slots,), 1)
-        self.emit("")
         self.make_constructor(product.fields, product)
         self.emit("")
         self.make_mutate_over(product, name)
@@ -106,15 +102,6 @@
         self.emit("")
         self.make_var_syncer(product.fields, product, name)
 
-    def make_slots(self, fields):
-        slots = []
-        for field in fields:
-            name = repr(field.name.value)
-            slots.append(name)
-            if field.seq:
-                slots.append("'w_%s'" % (field.name,))
-        return ", ".join(slots)
-
     def make_var_syncer(self, fields, node, name):
         self.emit("def sync_app_attrs(self, space):", 1)
         config = (self.data.optional_masks[node],
@@ -208,9 +195,6 @@
     def visitConstructor(self, cons, base, extra_attributes):
         self.emit("class %s(%s):" % (cons.name, base))
         self.emit("")
-        slots = self.make_slots(cons.fields)
-        self.emit("__slots__ = (%s)" % (slots,), 1)
-        self.emit("")
         for field in self.data.cons_attributes[cons]:
             subst = (field.name, self.data.field_masks[field])
             self.emit("_%s_mask = %i" % subst, 1)

diff --git a/pypy/interpreter/astcompiler/ast.py b/pypy/interpreter/astcompiler/ast.py
--- a/pypy/interpreter/astcompiler/ast.py
+++ b/pypy/interpreter/astcompiler/ast.py
@@ -14,9 +14,6 @@
 
     __metaclass__ = extendabletype
 
-    def __init__(self):
-        self.w_dict = None
-
     def walkabout(self, visitor):
         raise AssertionError("walkabout() implementation not provided")
 
@@ -75,13 +72,10 @@
 
 
 class mod(AST):
-
-    __slots__ = ()
+    pass
 
 class Module(mod):
 
-    __slots__ = ('body', 'w_body')
-
 
     def __init__(self, body):
         self.body = body
@@ -115,8 +109,6 @@
 
 class Interactive(mod):
 
-    __slots__ = ('body', 'w_body')
-
 
     def __init__(self, body):
         self.body = body
@@ -150,8 +142,6 @@
 
 class Expression(mod):
 
-    __slots__ = ('body')
-
 
     def __init__(self, body):
         self.body = body
@@ -174,8 +164,6 @@
 
 class Suite(mod):
 
-    __slots__ = ('body', 'w_body')
-
 
     def __init__(self, body):
         self.body = body
@@ -208,18 +196,12 @@
 
 
 class stmt(AST):
-
-    __slots__ = ('lineno', 'col_offset')
-
     def __init__(self, lineno, col_offset):
-        AST.__init__(self)
         self.lineno = lineno
         self.col_offset = col_offset
 
 class FunctionDef(stmt):
 
-    __slots__ = ('name', 'args', 'body', 'w_body', 'decorator_list', 'w_decorator_list')
-
     _lineno_mask = 16
     _col_offset_mask = 32
 
@@ -274,8 +256,6 @@
 
 class ClassDef(stmt):
 
-    __slots__ = ('name', 'bases', 'w_bases', 'body', 'w_body', 'decorator_list', 'w_decorator_list')
-
     _lineno_mask = 16
     _col_offset_mask = 32
 
@@ -341,8 +321,6 @@
 
 class Return(stmt):
 
-    __slots__ = ('value')
-
     _lineno_mask = 2
     _col_offset_mask = 4
 
@@ -371,8 +349,6 @@
 
 class Delete(stmt):
 
-    __slots__ = ('targets', 'w_targets')
-
     _lineno_mask = 2
     _col_offset_mask = 4
 
@@ -409,8 +385,6 @@
 
 class Assign(stmt):
 
-    __slots__ = ('targets', 'w_targets', 'value')
-
     _lineno_mask = 4
     _col_offset_mask = 8
 
@@ -450,8 +424,6 @@
 
 class AugAssign(stmt):
 
-    __slots__ = ('target', 'op', 'value')
-
     _lineno_mask = 8
     _col_offset_mask = 16
 
@@ -481,8 +453,6 @@
 
 class Print(stmt):
 
-    __slots__ = ('dest', 'values', 'w_values', 'nl')
-
     _lineno_mask = 8
     _col_offset_mask = 16
 
@@ -526,8 +496,6 @@
 
 class For(stmt):
 
-    __slots__ = ('target', 'iter', 'body', 'w_body', 'orelse', 'w_orelse')
-
     _lineno_mask = 16
     _col_offset_mask = 32
 
@@ -584,8 +552,6 @@
 
 class While(stmt):
 
-    __slots__ = ('test', 'body', 'w_body', 'orelse', 'w_orelse')
-
     _lineno_mask = 8
     _col_offset_mask = 16
 
@@ -639,8 +605,6 @@
 
 class If(stmt):
 
-    __slots__ = ('test', 'body', 'w_body', 'orelse', 'w_orelse')
-
     _lineno_mask = 8
     _col_offset_mask = 16
 
@@ -694,8 +658,6 @@
 
 class With(stmt):
 
-    __slots__ = ('context_expr', 'optional_vars', 'body', 'w_body')
-
     _lineno_mask = 8
     _col_offset_mask = 16
 
@@ -741,8 +703,6 @@
 
 class Raise(stmt):
 
-    __slots__ = ('type', 'inst', 'tback')
-
     _lineno_mask = 8
     _col_offset_mask = 16
 
@@ -785,8 +745,6 @@
 
 class TryExcept(stmt):
 
-    __slots__ = ('body', 'w_body', 'handlers', 'w_handlers', 'orelse', 'w_orelse')
-
     _lineno_mask = 8
     _col_offset_mask = 16
 
@@ -851,8 +809,6 @@
 
 class TryFinally(stmt):
 
-    __slots__ = ('body', 'w_body', 'finalbody', 'w_finalbody')
-
     _lineno_mask = 4
     _col_offset_mask = 8
 
@@ -903,8 +859,6 @@
 
 class Assert(stmt):
 
-    __slots__ = ('test', 'msg')
-
     _lineno_mask = 4
     _col_offset_mask = 8
 
@@ -936,8 +890,6 @@
 
 class Import(stmt):
 
-    __slots__ = ('names', 'w_names')
-
     _lineno_mask = 2
     _col_offset_mask = 4
 
@@ -974,8 +926,6 @@
 
 class ImportFrom(stmt):
 
-    __slots__ = ('module', 'names', 'w_names', 'level')
-
     _lineno_mask = 8
     _col_offset_mask = 16
 
@@ -1017,8 +967,6 @@
 
 class Exec(stmt):
 
-    __slots__ = ('body', 'globals', 'locals')
-
     _lineno_mask = 8
     _col_offset_mask = 16
 
@@ -1057,8 +1005,6 @@
 
 class Global(stmt):
 
-    __slots__ = ('names', 'w_names')
-
     _lineno_mask = 2
     _col_offset_mask = 4
 
@@ -1090,8 +1036,6 @@
 
 class Expr(stmt):
 
-    __slots__ = ('value')
-
     _lineno_mask = 2
     _col_offset_mask = 4
 
@@ -1117,8 +1061,6 @@
 
 class Pass(stmt):
 
-    __slots__ = ()
-
     _lineno_mask = 1
     _col_offset_mask = 2
 
@@ -1141,8 +1083,6 @@
 
 class Break(stmt):
 
-    __slots__ = ()
-
     _lineno_mask = 1
     _col_offset_mask = 2
 
@@ -1165,8 +1105,6 @@
 
 class Continue(stmt):
 
-    __slots__ = ()
-
     _lineno_mask = 1
     _col_offset_mask = 2
 
@@ -1188,18 +1126,12 @@
 
 
 class expr(AST):
-
-    __slots__ = ('lineno', 'col_offset')
-
     def __init__(self, lineno, col_offset):
-        AST.__init__(self)
         self.lineno = lineno
         self.col_offset = col_offset
 
 class BoolOp(expr):
 
-    __slots__ = ('op', 'values', 'w_values')
-
     _lineno_mask = 4
     _col_offset_mask = 8
 
@@ -1237,8 +1169,6 @@
 
 class BinOp(expr):
 
-    __slots__ = ('left', 'op', 'right')
-
     _lineno_mask = 8
     _col_offset_mask = 16
 
@@ -1268,8 +1198,6 @@
 
 class UnaryOp(expr):
 
-    __slots__ = ('op', 'operand')
-
     _lineno_mask = 4
     _col_offset_mask = 8
 
@@ -1296,8 +1224,6 @@
 
 class Lambda(expr):
 
-    __slots__ = ('args', 'body')
-
     _lineno_mask = 4
     _col_offset_mask = 8
 
@@ -1326,8 +1252,6 @@
 
 class IfExp(expr):
 
-    __slots__ = ('test', 'body', 'orelse')
-
     _lineno_mask = 8
     _col_offset_mask = 16
 
@@ -1359,8 +1283,6 @@
 
 class Dict(expr):
 
-    __slots__ = ('keys', 'w_keys', 'values', 'w_values')
-
     _lineno_mask = 4
     _col_offset_mask = 8
 
@@ -1411,8 +1333,6 @@
 
 class Set(expr):
 
-    __slots__ = ('elts', 'w_elts')
-
     _lineno_mask = 2
     _col_offset_mask = 4
 
@@ -1449,8 +1369,6 @@
 
 class ListComp(expr):
 
-    __slots__ = ('elt', 'generators', 'w_generators')
-
     _lineno_mask = 4
     _col_offset_mask = 8
 
@@ -1490,8 +1408,6 @@
 
 class SetComp(expr):
 
-    __slots__ = ('elt', 'generators', 'w_generators')
-
     _lineno_mask = 4
     _col_offset_mask = 8
 
@@ -1531,8 +1447,6 @@
 
 class DictComp(expr):
 
-    __slots__ = ('key', 'value', 'generators', 'w_generators')
-
     _lineno_mask = 8
     _col_offset_mask = 16
 
@@ -1575,8 +1489,6 @@
 
 class GeneratorExp(expr):
 
-    __slots__ = ('elt', 'generators', 'w_generators')
-
     _lineno_mask = 4
     _col_offset_mask = 8
 
@@ -1616,8 +1528,6 @@
 
 class Yield(expr):
 
-    __slots__ = ('value')
-
     _lineno_mask = 2
     _col_offset_mask = 4
 
@@ -1646,8 +1556,6 @@
 
 class Compare(expr):
 
-    __slots__ = ('left', 'ops', 'w_ops', 'comparators', 'w_comparators')
-
     _lineno_mask = 8
     _col_offset_mask = 16
 
@@ -1696,8 +1604,6 @@
 
 class Call(expr):
 
-    __slots__ = ('func', 'args', 'w_args', 'keywords', 'w_keywords', 'starargs', 'kwargs')
-
     _lineno_mask = 32
     _col_offset_mask = 64
 
@@ -1764,8 +1670,6 @@
 
 class Repr(expr):
 
-    __slots__ = ('value')
-
     _lineno_mask = 2
     _col_offset_mask = 4
 
@@ -1791,8 +1695,6 @@
 
 class Num(expr):
 
-    __slots__ = ('n')
-
     _lineno_mask = 2
     _col_offset_mask = 4
 
@@ -1816,8 +1718,6 @@
 
 class Str(expr):
 
-    __slots__ = ('s')
-
     _lineno_mask = 2
     _col_offset_mask = 4
 
@@ -1841,8 +1741,6 @@
 
 class Attribute(expr):
 
-    __slots__ = ('value', 'attr', 'ctx')
-
     _lineno_mask = 8
     _col_offset_mask = 16
 
@@ -1870,8 +1768,6 @@
 
 class Subscript(expr):
 
-    __slots__ = ('value', 'slice', 'ctx')
-
     _lineno_mask = 8
     _col_offset_mask = 16
 
@@ -1901,8 +1797,6 @@
 
 class Name(expr):
 
-    __slots__ = ('id', 'ctx')
-
     _lineno_mask = 4
     _col_offset_mask = 8
 
@@ -1927,8 +1821,6 @@
 
 class List(expr):
 
-    __slots__ = ('elts', 'w_elts', 'ctx')
-
     _lineno_mask = 4
     _col_offset_mask = 8
 
@@ -1966,8 +1858,6 @@
 
 class Tuple(expr):
 
-    __slots__ = ('elts', 'w_elts', 'ctx')
-
     _lineno_mask = 4
     _col_offset_mask = 8
 
@@ -2005,8 +1895,6 @@
 
 class Const(expr):
 
-    __slots__ = ('value')
-
     _lineno_mask = 2
     _col_offset_mask = 4
 
@@ -2081,16 +1969,12 @@
 ]
 
 class slice(AST):
-
-    __slots__ = ()
+    pass
 
 class Ellipsis(slice):
 
-    __slots__ = ()
-
 
     def __init__(self):
-        AST.__init__(self)
         self.initialization_state = 0
 
     def walkabout(self, visitor):
@@ -2108,8 +1992,6 @@
 
 class Slice(slice):
 
-    __slots__ = ('lower', 'upper', 'step')
-
 
     def __init__(self, lower, upper, step):
         self.lower = lower
@@ -2149,8 +2031,6 @@
 
 class ExtSlice(slice):
 
-    __slots__ = ('dims', 'w_dims')
-
 
     def __init__(self, dims):
         self.dims = dims
@@ -2184,8 +2064,6 @@
 
 class Index(slice):
 
-    __slots__ = ('value')
-
 
     def __init__(self, value):
         self.value = value
@@ -2444,8 +2322,6 @@
 
 class comprehension(AST):
 
-    __slots__ = ('target', 'iter', 'ifs', 'w_ifs')
-
     def __init__(self, target, iter, ifs):
         self.target = target
         self.iter = iter
@@ -2482,18 +2358,12 @@
                 node.sync_app_attrs(space)
 
 class excepthandler(AST):
-
-    __slots__ = ('lineno', 'col_offset')
-
     def __init__(self, lineno, col_offset):
-        AST.__init__(self)
         self.lineno = lineno
         self.col_offset = col_offset
 
 class ExceptHandler(excepthandler):
 
-    __slots__ = ('type', 'name', 'body', 'w_body')
-
     _lineno_mask = 8
     _col_offset_mask = 16
 
@@ -2543,8 +2413,6 @@
 
 class arguments(AST):
 
-    __slots__ = ('args', 'w_args', 'vararg', 'kwarg', 'defaults', 'w_defaults')
-
     def __init__(self, args, vararg, kwarg, defaults):
         self.args = args
         self.w_args = None
@@ -2595,8 +2463,6 @@
 
 class keyword(AST):
 
-    __slots__ = ('arg', 'value')
-
     def __init__(self, arg, value):
         self.arg = arg
         self.value = value
@@ -2618,8 +2484,6 @@
 
 class alias(AST):
 
-    __slots__ = ('name', 'asname')
-
     def __init__(self, name, asname):
         self.name = name
         self.asname = asname


More information about the Pypy-commit mailing list