Author: Ronan Lamy <[email protected]>
Branch: 
Changeset: r71740:b13ff9f02cb0
Date: 2014-05-27 04:01 +0100
http://bitbucket.org/pypy/pypy/changeset/b13ff9f02cb0/

Log:    kill pbc.isNone()

diff --git a/rpython/annotator/model.py b/rpython/annotator/model.py
--- a/rpython/annotator/model.py
+++ b/rpython/annotator/model.py
@@ -472,9 +472,6 @@
         if len(self.descriptions) > 1:
             kind.simplify_desc_set(self.descriptions)
 
-    def isNone(self):
-        return False
-
     def can_be_none(self):
         return self.can_be_None
 
@@ -502,9 +499,6 @@
     def __init__(self):
         pass
 
-    def isNone(self):
-        return True
-
     @property
     def descriptions(self):
         return set()
diff --git a/rpython/annotator/unaryop.py b/rpython/annotator/unaryop.py
--- a/rpython/annotator/unaryop.py
+++ b/rpython/annotator/unaryop.py
@@ -739,8 +739,7 @@
     getattr.can_only_throw = []
 
     def setattr(self, s_attr, s_value):
-        if not self.isNone():
-            raise AnnotatorError("Cannot modify attribute of a pre-built 
constant")
+        raise AnnotatorError("Cannot modify attribute of a pre-built constant")
 
     def call(self, args):
         bookkeeper = getbookkeeper()
@@ -751,24 +750,27 @@
         return SomePBC(d, can_be_None=self.can_be_None)
 
     def bool_behavior(self, s):
-        if self.isNone():
-            s.const = False
-        elif not self.can_be_None:
+        if not self.can_be_None:
             s.const = True
 
     def len(self):
-        if self.isNone():
-            # this None could later be generalized into an empty list,
-            # whose length is the constant 0; so let's tentatively answer 0.
-            return immutablevalue(0)
-        else:
-            # This should probably never happen
-            raise AnnotatorError("Cannot call len on a pbc")
+        raise AnnotatorError("Cannot call len on a pbc")
 
 class __extend__(SomeNone):
     def bind_callables_under(self, classdef, name):
         return self
 
+    def setattr(self, s_attr, s_value):
+        return None
+
+    def bool_behavior(self, s):
+        s.const = False
+
+    def len(self):
+        # XXX: this None could later be generalized into an empty list,
+        # whose length is the constant 0; so let's tentatively answer 0.
+        return immutablevalue(0)
+
 #_________________________________________
 # weakrefs
 
diff --git a/rpython/rtyper/rclass.py b/rpython/rtyper/rclass.py
--- a/rpython/rtyper/rclass.py
+++ b/rpython/rtyper/rclass.py
@@ -154,11 +154,12 @@
         # special-casing for methods:
         #  if s_value is SomePBC([MethodDescs...])
         #  return a PBC representing the underlying functions
-        if isinstance(s_value, annmodel.SomePBC):
-            if not s_value.isNone() and s_value.getKind() == 
description.MethodDesc:
-                s_value = self.classdef.lookup_filter(s_value)
-                funcdescs = [mdesc.funcdesc for mdesc in s_value.descriptions]
-                return annmodel.SomePBC(funcdescs)
+        if (isinstance(s_value, annmodel.SomePBC) and
+                not isinstance(s_value, annmodel.SomeNone) and
+                s_value.getKind() == description.MethodDesc):
+            s_value = self.classdef.lookup_filter(s_value)
+            funcdescs = [mdesc.funcdesc for mdesc in s_value.descriptions]
+            return annmodel.SomePBC(funcdescs)
         return None   # not a method
 
     def get_ll_eq_function(self):
diff --git a/rpython/rtyper/rpbc.py b/rpython/rtyper/rpbc.py
--- a/rpython/rtyper/rpbc.py
+++ b/rpython/rtyper/rpbc.py
@@ -25,8 +25,6 @@
         from rpython.rtyper.lltypesystem.rpbc import (FunctionsPBCRepr,
             SmallFunctionSetPBCRepr, ClassesPBCRepr, MethodsPBCRepr,
             MethodOfFrozenPBCRepr)
-        if self.isNone():
-            return none_frozen_pbc_repr
         kind = self.getKind()
         if issubclass(kind, description.FunctionDesc):
             sample = self.any_description()
@@ -63,6 +61,13 @@
             t = ()
         return tuple([self.__class__, self.can_be_None]+lst)+t
 
+class __extend__(annmodel.SomeNone):
+    def rtyper_makerepr(self, rtyper):
+        return none_frozen_pbc_repr
+
+    def rtyper_makekey(self):
+        return self.__class__,
+
 # ____________________________________________________________
 
 class ConcreteCallTableRow(dict):
@@ -808,9 +813,6 @@
     def __init__(self, rtyper, s_pbc):
         self.rtyper = rtyper
         self.s_pbc = s_pbc
-        if s_pbc.isNone():
-            raise TyperError("unsupported: variable of type "
-                             "bound-method-object or None")
         mdescs = list(s_pbc.descriptions)
         methodname = mdescs[0].name
         classdef = mdescs[0].selfclassdef
diff --git a/rpython/translator/goal/query.py b/rpython/translator/goal/query.py
--- a/rpython/translator/goal/query.py
+++ b/rpython/translator/goal/query.py
@@ -61,7 +61,7 @@
     def ismeth(s_val):
         if not isinstance(s_val, annmodel.SomePBC):
             return False
-        if s_val.isNone():
+        if isinstance(s_val, annmodel.SomeNone):
             return False
         return s_val.getKind() is MethodDesc
     bk = translator.annotator.bookkeeper
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to