Author: Ronan Lamy <[email protected]>
Branch: anntype
Changeset: r80765:37f7ff034ec7
Date: 2015-11-18 20:11 +0000
http://bitbucket.org/pypy/pypy/changeset/37f7ff034ec7/
Log: Completely move is_type_of attribute from SomeType to SomeTypeOf
diff --git a/rpython/annotator/annrpython.py b/rpython/annotator/annrpython.py
--- a/rpython/annotator/annrpython.py
+++ b/rpython/annotator/annrpython.py
@@ -11,7 +11,7 @@
from rpython.translator import simplify, transform
from rpython.annotator import model as annmodel, signature
from rpython.annotator.model import (
- SomeTypeOf, SomeException, SomeExceptCase, s_ImpossibleValue)
+ typeof, SomeTypeOf, SomeException, SomeExceptCase, s_ImpossibleValue)
from rpython.annotator.bookkeeper import Bookkeeper
from rpython.rtyper.normalizecalls import perform_normalizations
@@ -395,11 +395,10 @@
for v in s_out.is_type_of:
renamed_is_type_of += renaming[v]
assert s_out.knowntype is type
- newcell = annmodel.SomeType()
+ newcell = typeof(renamed_is_type_of)
if s_out.is_constant():
newcell.const = s_out.const
s_out = newcell
- s_out.is_type_of = renamed_is_type_of
if hasattr(s_out, 'knowntypedata'):
renamed_knowntypedata = {}
@@ -573,7 +572,7 @@
self.setbinding(v_last_exc_value, s_last_exc_value)
if isinstance(v_last_exc_type, Variable):
- self.setbinding(v_last_exc_type, SomeTypeOf(v_last_exc_value))
+ self.setbinding(v_last_exc_type, SomeTypeOf([v_last_exc_value]))
ignore_link = False
@@ -584,8 +583,7 @@
for v_out, v_input in zip(link.args, link.target.inputargs):
if v_out == v_last_exc_type:
- s_out = annmodel.SomeType()
- s_out.is_type_of = renaming[v_last_exc_value]
+ s_out = typeof(renaming[v_last_exc_value])
if isinstance(v_last_exc_type, Constant):
s_out.const = v_last_exc_type.value
inputs_s.append(s_out)
diff --git a/rpython/annotator/binaryop.py b/rpython/annotator/binaryop.py
--- a/rpython/annotator/binaryop.py
+++ b/rpython/annotator/binaryop.py
@@ -146,25 +146,18 @@
def union((obj1, obj2)):
result = SomeType()
- is_type_of1 = getattr(obj1, 'is_type_of', [])
- is_type_of2 = getattr(obj2, 'is_type_of', [])
if obj1.is_immutable_constant() and obj2.is_immutable_constant() and
obj1.const == obj2.const:
result.const = obj1.const
- if is_type_of1 and is_type_of1 == is_type_of2:
- result.is_type_of = is_type_of1
return result
class __extend__(pairtype(SomeTypeOf, SomeTypeOf)):
def union((s_obj1, s_obj2)):
- if s_obj1 == s_obj2:
- return s_obj1
- else:
- s_1 = SomeType()
- s_1.is_type_of = s_obj1.is_type_of
- s_2 = SomeType()
- s_2.is_type_of = s_obj2.is_type_of
- return unionof(s_1, s_2)
-
+ vars = list(set(s_obj1.is_type_of) | set(s_obj2.is_type_of))
+ result = SomeTypeOf(vars)
+ if (s_obj1.is_immutable_constant() and s_obj2.is_immutable_constant()
+ and s_obj1.const == s_obj2.const):
+ result.const = obj1.const
+ return result
# cloning a function with identical code, for the can_only_throw attribute
def _clone(f, can_only_throw = None):
diff --git a/rpython/annotator/model.py b/rpython/annotator/model.py
--- a/rpython/annotator/model.py
+++ b/rpython/annotator/model.py
@@ -140,12 +140,17 @@
class SomeTypeOf(SomeType):
"""The type of a variable"""
- def __init__(self, v_arg):
- self.v_arg = v_arg
+ def __init__(self, args_v):
+ assert isinstance(args_v, list)
+ assert args_v
+ self.is_type_of = args_v
- @property
- def is_type_of(self):
- return [self.v_arg]
+def typeof(args_v):
+ if args_v:
+ return SomeTypeOf(args_v)
+ else:
+ return SomeType()
+
class SomeFloat(SomeObject):
"Stands for a float or an integer."
diff --git a/rpython/annotator/test/test_annrpython.py
b/rpython/annotator/test/test_annrpython.py
--- a/rpython/annotator/test/test_annrpython.py
+++ b/rpython/annotator/test/test_annrpython.py
@@ -709,7 +709,7 @@
graph = graphof(a, f)
etype, evalue = graph.exceptblock.inputargs
assert evalue.annotation.classdef.shortname == 'IndexError'
- #assert etype.const == IndexError
+ #assert etype.annotation.const == IndexError
def test_operation_always_raising(self):
def operation_always_raising(n):
@@ -1389,11 +1389,12 @@
a.build_types(f, [somedict(annmodel.s_Int, annmodel.s_Int)])
fg = graphof(a, f)
et, ev = fg.exceptblock.inputargs
- t = annmodel.SomeType()
+ t = annmodel.SomeTypeOf([ev])
t.const = KeyError
- t.is_type_of = [ev]
- assert a.binding(et) == t
- assert isinstance(a.binding(ev), annmodel.SomeInstance) and
a.binding(ev).classdef == a.bookkeeper.getuniqueclassdef(KeyError)
+ assert et.annotation == t
+ s_ev = ev.annotation
+ assert (isinstance(s_ev, annmodel.SomeInstance) and
+ s_ev.classdef == a.bookkeeper.getuniqueclassdef(KeyError))
def test_reraiseAnything(self):
def f(dic):
@@ -1405,11 +1406,12 @@
a.build_types(f, [somedict(annmodel.s_Int, annmodel.s_Int)])
fg = graphof(a, f)
et, ev = fg.exceptblock.inputargs
- t = annmodel.SomeType()
- t.is_type_of = [ev]
- t.const = KeyError # IndexError ignored because 'dic' is a dict
- assert a.binding(et) == t
- assert isinstance(a.binding(ev), annmodel.SomeInstance) and
a.binding(ev).classdef == a.bookkeeper.getuniqueclassdef(KeyError)
+ t = annmodel.SomeTypeOf([ev])
+ t.const = KeyError # IndexError ignored because 'dic' is a dict
+ assert et.annotation == t
+ s_ev = ev.annotation
+ assert (isinstance(s_ev, annmodel.SomeInstance) and
+ s_ev.classdef == a.bookkeeper.getuniqueclassdef(KeyError))
def test_exception_mixing(self):
def h():
@@ -1440,10 +1442,11 @@
a.build_types(f, [int, somelist(annmodel.s_Int)])
fg = graphof(a, f)
et, ev = fg.exceptblock.inputargs
- t = annmodel.SomeType()
- t.is_type_of = [ev]
- assert a.binding(et) == t
- assert isinstance(a.binding(ev), annmodel.SomeInstance) and
a.binding(ev).classdef == a.bookkeeper.getuniqueclassdef(Exception)
+ t = annmodel.SomeTypeOf([ev])
+ assert et.annotation == t
+ s_ev = ev.annotation
+ assert (isinstance(s_ev, annmodel.SomeInstance) and
+ s_ev.classdef == a.bookkeeper.getuniqueclassdef(Exception))
def test_try_except_raise_finally1(self):
def h(): pass
@@ -1462,10 +1465,11 @@
a.build_types(f, [])
fg = graphof(a, f)
et, ev = fg.exceptblock.inputargs
- t = annmodel.SomeType()
- t.is_type_of = [ev]
- assert a.binding(et) == t
- assert isinstance(a.binding(ev), annmodel.SomeInstance) and
a.binding(ev).classdef == a.bookkeeper.getuniqueclassdef(Exception)
+ t = annmodel.SomeTypeOf([ev])
+ assert et.annotation == t
+ s_ev = ev.annotation
+ assert (isinstance(s_ev, annmodel.SomeInstance) and
+ s_ev.classdef == a.bookkeeper.getuniqueclassdef(Exception))
def test_inplace_div(self):
def f(n):
diff --git a/rpython/annotator/unaryop.py b/rpython/annotator/unaryop.py
--- a/rpython/annotator/unaryop.py
+++ b/rpython/annotator/unaryop.py
@@ -30,7 +30,7 @@
@op.type.register(SomeObject)
def type_SomeObject(annotator, v_arg):
- return SomeTypeOf(v_arg)
+ return SomeTypeOf([v_arg])
@op.bool.register(SomeObject)
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
@@ -48,7 +48,7 @@
s_ev = annotator.annotation(ev)
if s_et:
if s_et.knowntype == type:
- if s_et.__class__ == annmodel.SomeType:
+ if s_et.__class__ == annmodel.SomeTypeOf:
if hasattr(s_et, 'is_type_of') and s_et.is_type_of ==
[ev]:
continue
else:
diff --git a/rpython/translator/transform.py b/rpython/translator/transform.py
--- a/rpython/translator/transform.py
+++ b/rpython/translator/transform.py
@@ -189,8 +189,7 @@
self.links_followed[errlink] = True
# fix the annotation of the exceptblock.inputargs
etype, evalue = graph.exceptblock.inputargs
- s_type = annmodel.SomeType()
- s_type.is_type_of = [evalue]
+ s_type = annmodel.SomeTypeOf([evalue])
s_value =
annmodel.SomeInstance(self.bookkeeper.getuniqueclassdef(Exception))
self.setbinding(etype, s_type)
self.setbinding(evalue, s_value)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit