Read about our upcoming Code of Conduct on this issue

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

create noneify() method to handle unions with s_None

parent 2898a860e1fa
......@@ -768,6 +768,22 @@ class __extend__(pairtype(SomeObject, SomeImpossibleValue)):
# mixing Nones with other objects
class __extend__(pairtype(SomeObject, SomeNone)):
def union((obj, none)):
return obj.noneify()
class __extend__(pairtype(SomeNone, SomeObject)):
def union((none, obj)):
return obj.noneify()
class __extend__(pairtype(SomeImpossibleValue, SomeNone)):
def union((imp1, none)):
return s_None
class __extend__(pairtype(SomeNone, SomeImpossibleValue)):
def union((none, imp2)):
return s_None
def _make_none_union(classname, constructor_args='', glob=None):
if glob is None:
glob = globals()
......@@ -122,6 +122,9 @@ class SomeObject(object):
def can_be_none(self):
return True
def noneify(self):
raise UnionError(self, s_None)
def nonnoneify(self):
return self
......@@ -476,7 +479,12 @@ class SomePBC(SomeObject):
return self.can_be_None
def nonnoneify(self):
return SomePBC(self.descriptions, can_be_None=False)
return SomePBC(self.descriptions, can_be_None=False,
def noneify(self):
return SomePBC(self.descriptions, can_be_None=True,
def fmt_descriptions(self, pbis):
if hasattr(self, 'const'):
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