From 20d96098c029f82942835c5d05f82e44a48d765e Mon Sep 17 00:00:00 2001
From: Alexandre Boeglin <alex@nexedi.com>
Date: Fri, 20 Oct 2006 13:03:03 +0000
Subject: [PATCH] - use isinstance() instead of type() == type() - if type is
 object, do not check, as it can be anything

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@10853 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../Constraint/PropertyTypeValidity.py        | 34 +++++++++++--------
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/product/ERP5Type/Constraint/PropertyTypeValidity.py b/product/ERP5Type/Constraint/PropertyTypeValidity.py
index c6f5f609c9..f85307ded6 100644
--- a/product/ERP5Type/Constraint/PropertyTypeValidity.py
+++ b/product/ERP5Type/Constraint/PropertyTypeValidity.py
@@ -32,9 +32,9 @@ from Constraint import Constraint
 from DateTime import DateTime
 
 try:
-  boolean_types = (type(1), type(True))
+  boolean_types = (int, bool)
 except NameError:
-  boolean_types = (type(1), )
+  boolean_types = (int, )
 
 class PropertyTypeValidity(Constraint):
   """
@@ -45,21 +45,23 @@ class PropertyTypeValidity(Constraint):
 
   # Initialize type dict
   _type_dict = {
-    'object':             (type('a'), ),
-    'string':             (type('a'), ),
-    'text':               (type('a'), ),
-    'int':                (type(1), ),
+    'string':             (str, ),
+    'text':               (str, ),
+    'int':                (int, ),
     'boolean':            boolean_types,
-    'float':              (type(1.0), ),
-    'long':               (type(1L), ),
-    'tales':              (type('string:3'), ),
-    'lines':              (type([]), type(())),
-    'tokens':             (type([]), type(())),
-    'selection':          (type([]), type(())),
-    'multiple selection': (type([]), type(())),
-    'date':               (type(DateTime()), ),
+    'float':              (float, ),
+    'long':               (long, ),
+    'tales':              (str, ),
+    'lines':              (list, tuple),
+    'tokens':             (list, tuple),
+    'selection':          (list, tuple),
+    'multiple selection': (list, tuple),
+    'date':               (DateTime, ),
   }
 
+  # Properties of type eg. "object" can hold anything
+  _permissive_type_list = ('object')
+
   def checkConsistency(self, obj, fixit=0):
     """
       This is the check method, we return a list of string,
@@ -73,6 +75,8 @@ class PropertyTypeValidity(Constraint):
         property_type = 'lines'
       else:
         property_type = prop['type']
+      if property_type in self._permissive_type_list:
+        continue
       wrong_type = 0
       if property_type == 'tales':
         value = obj.getProperty(property_id, evaluate=0)
@@ -81,7 +85,7 @@ class PropertyTypeValidity(Constraint):
       if value is not None:
         # Check known type
         try:
-          wrong_type = (type(value) not in self._type_dict[property_type])
+          wrong_type = not isinstance(value, self._type_dict[property_type])
         except KeyError:
           wrong_type = 0
           error_message = "Attribute %s is defined with unknown type %s" % \
-- 
2.30.9