[Zope3-checkins] CVS: Zope3/src/zope/proxy - __init__.py:1.4
Barry Warsaw
barry@zope.com
Thu, 17 Apr 2003 11:19:00 -0400
Update of /cvs-repository/Zope3/src/zope/proxy
In directory cvs.zope.org:/tmp/cvs-serv5517
Modified Files:
__init__.py
Log Message:
proxy_compatible_isinstance(): We have to remove all proxies from the
object's __class__ before we can test it with issubclass().
Also, a few minor code cleanups.
=== Zope3/src/zope/proxy/__init__.py 1.3 => 1.4 ===
--- Zope3/src/zope/proxy/__init__.py:1.3 Wed Apr 16 15:32:43 2003
+++ Zope3/src/zope/proxy/__init__.py Thu Apr 17 11:19:00 2003
@@ -16,6 +16,9 @@
$Id$
"""
+from zope.proxy.introspection import removeAllProxies
+
+
def proxy_compatible_isinstance(obj, cls):
"""Like built-in isinstance() in Python 2.3.
@@ -24,9 +27,9 @@
"""
if isinstance(obj, cls):
return True
- oclass = obj.__class__
- if type(obj) == oclass:
- # Nothing more we can do
+ oclass = removeAllProxies(obj.__class__)
+ if type(obj) is oclass:
+ # Nothing more will help
return False
# Note that cls may be a tuple, but issubclass can't deal with that so we
# need to expand recursively.
@@ -37,7 +40,7 @@
if thisclass in classes:
continue
if isinstance(thisclass, tuple):
- flatten.extend(list(thisclass))
+ flatten.extend(thisclass)
else:
classes[thisclass] = True
for bclass in classes.keys():