Read about our upcoming Code of Conduct on this issue

Commit e9e8a073 authored by Ronan Lamy's avatar Ronan Lamy
Browse files

kill pbc.isNone()

parent 181bc0186716
......@@ -472,9 +472,6 @@ class SomePBC(SomeObject):
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 @@ class SomeNone(SomePBC):
def __init__(self):
pass
def isNone(self):
return True
@property
def descriptions(self):
return set()
......
......@@ -739,8 +739,7 @@ class __extend__(SomePBC):
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 @@ class __extend__(SomePBC):
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
......
......@@ -154,11 +154,12 @@ class AbstractClassRepr(Repr):
# 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):
......
......@@ -25,8 +25,6 @@ class __extend__(annmodel.SomePBC):
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 @@ class __extend__(annmodel.SomePBC):
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 @@ class AbstractMethodsPBCRepr(Repr):
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
......
......@@ -61,7 +61,7 @@ def check_methods_qgen(translator):
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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment