[Zope3-checkins] CVS: Zope3/lib/python/Zope/Schema - FieldProperty.py:1.2

Jim Fulton jim@zope.com
Sun, 8 Sep 2002 09:52:13 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/Schema
In directory cvs.zope.org:/tmp/cvs-serv19734/lib/python/Zope/Schema

Modified Files:
	FieldProperty.py 
Log Message:
Changed FieldProperty to store it's data in instance dictionaries
with keys of the same name as the property, rather than using a munged
name. This will lead to less surprizes, at the cost of a dependency on
being anle to access and update instance dictionaries.


=== Zope3/lib/python/Zope/Schema/FieldProperty.py 1.1 => 1.2 ===
--- Zope3/lib/python/Zope/Schema/FieldProperty.py:1.1	Sat Sep  7 12:18:51 2002
+++ Zope3/lib/python/Zope/Schema/FieldProperty.py	Sun Sep  8 09:52:13 2002
@@ -24,6 +24,10 @@
 
     Field properties provide default values, data validation and error messages
     based on data found in field meta-data.
+
+    Note that FieldProperties cannot be used with slots. They can only
+    be used for attributes stored in instance dictionaries.
+    
     """
 
     def __init__(self, field, name=None):
@@ -32,13 +36,12 @@
 
         self.__field = field
         self.__name = name
-        self.__private_name = "_fp__" + name
 
     def __get__(self, inst, klass):
         if inst is None:
             return self
 
-        value = getattr(inst, self.__private_name, _marker)
+        value = inst.__dict__.get(self.__name, _marker)
         if value is _marker:
             value = getattr(self.__field, 'default', _marker)
             if value is _marker:
@@ -48,7 +51,7 @@
 
     def __set__(self, inst, value):
         self.__field.validate(value)
-        setattr(inst, self.__private_name, value)
+        inst.__dict__[self.__name] = value
             
 
 __doc__ = FieldProperty.__doc__ + __doc__