[pypy-svn] r32576 - in pypy/dist/pypy: annotation annotation/test translator/test
arigo at codespeak.net
arigo at codespeak.net
Fri Sep 22 13:49:55 CEST 2006
Author: arigo
Date: Fri Sep 22 13:49:53 2006
New Revision: 32576
Modified:
pypy/dist/pypy/annotation/bookkeeper.py
pypy/dist/pypy/annotation/classdef.py
pypy/dist/pypy/annotation/test/test_annrpython.py
pypy/dist/pypy/translator/test/snippet.py
Log:
(arre, arigo)
Annotator fix for prebuilt instances of classes with __slots__.
Modified: pypy/dist/pypy/annotation/bookkeeper.py
==============================================================================
--- pypy/dist/pypy/annotation/bookkeeper.py (original)
+++ pypy/dist/pypy/annotation/bookkeeper.py Fri Sep 22 13:49:53 2006
@@ -614,7 +614,7 @@
self.seen_mutable[x] = True
self.event('mutable', x)
source = InstanceSource(self, x)
- for attr in x.__dict__:
+ for attr in source.all_instance_attributes():
clsdef.add_source_for_attribute(attr, source) # can trigger reflowing
def valueoftype(self, t):
Modified: pypy/dist/pypy/annotation/classdef.py
==============================================================================
--- pypy/dist/pypy/annotation/classdef.py (original)
+++ pypy/dist/pypy/annotation/classdef.py Fri Sep 22 13:49:53 2006
@@ -413,10 +413,22 @@
self.obj = obj
def s_get_value(self, classdef, name):
- s_value = self.bookkeeper.immutablevalue(
- self.obj.__dict__[name])
+ s_value = self.bookkeeper.immutablevalue(getattr(self.obj, name))
return s_value
+ def all_instance_attributes(self):
+ result = getattr(self.obj, '__dict__', {}).keys()
+ tp = self.obj.__class__
+ if isinstance(tp, type):
+ for basetype in tp.__mro__:
+ slots = basetype.__dict__.get('__slots__')
+ if slots:
+ if isinstance(slots, str):
+ result.append(slots)
+ else:
+ result.extend(slots)
+ return result
+
class NoSuchSlotError(Exception):
"Raised when an attribute is found on a class where __slots__ forbits it."
Modified: pypy/dist/pypy/annotation/test/test_annrpython.py
==============================================================================
--- pypy/dist/pypy/annotation/test/test_annrpython.py (original)
+++ pypy/dist/pypy/annotation/test/test_annrpython.py Fri Sep 22 13:49:53 2006
@@ -373,6 +373,12 @@
assert s == annmodel.SomeInteger(nonneg=True)
#self.assertEquals(s.__class__, annmodel.SomeInteger)
+ def test_pbc_attr_preserved_on_instance_with_slots(self):
+ a = self.RPythonAnnotator()
+ s = a.build_types(snippet.preserve_pbc_attr_on_instance_with_slots,
+ [bool])
+ assert s == annmodel.SomeInteger(nonneg=True)
+
def test_is_and_knowntype_data(self):
a = self.RPythonAnnotator()
s = a.build_types(snippet.is_and_knowntype, [str])
Modified: pypy/dist/pypy/translator/test/snippet.py
==============================================================================
--- pypy/dist/pypy/translator/test/snippet.py (original)
+++ pypy/dist/pypy/translator/test/snippet.py Fri Sep 22 13:49:53 2006
@@ -715,6 +715,22 @@
return x.answer
+class APBCS(object):
+ __slots__ = ['answer']
+ def __init__(self):
+ self.answer = 42
+
+apbcs = APBCS()
+apbcs.answer = 7
+
+def preserve_pbc_attr_on_instance_with_slots(cond):
+ if cond:
+ x = APBCS()
+ else:
+ x = apbcs
+ return x.answer
+
+
def is_and_knowntype(x):
if x is None:
return x
More information about the Pypy-commit
mailing list