61: Proxy now does a setattr for all callable attributes in __slots__ (and uses __getattr__ for rest

This commit is contained in:
Jason Gerard DeRose 2008-08-06 14:59:54 +00:00
parent 293b31ac75
commit 4e825ba2d9
2 changed files with 7 additions and 5 deletions

View File

@ -131,7 +131,6 @@ class Proxy(ReadOnly):
""" """
__slots__ = ( __slots__ = (
'__call__',
'__obj', '__obj',
'name', 'name',
) )
@ -145,10 +144,10 @@ class Proxy(ReadOnly):
check_identifier(proxy_name) check_identifier(proxy_name)
object.__setattr__(self, '_Proxy__obj', obj) object.__setattr__(self, '_Proxy__obj', obj)
object.__setattr__(self, 'name', proxy_name) object.__setattr__(self, 'name', proxy_name)
if callable(obj): for name in self.__slots__:
object.__setattr__(self, '__call__', obj.__call__) attr = getattr(obj, name)
#for name in self.__slots__: if callable(attr):
# object.__setattr__(self, name, getattr(obj, name)) object.__setattr__(self, name, attr)
def __repr__(self): def __repr__(self):
return '%s(%r)' % (self.__class__.__name__, self.__obj) return '%s(%r)' % (self.__class__.__name__, self.__obj)

View File

@ -62,6 +62,9 @@ def test_valid_identifier():
def test_Plugin(): def test_Plugin():
cls = plugable.Plugin
assert type(cls.name) is property
api = 'the api instance' api = 'the api instance'
p = plugable.Plugin() p = plugable.Plugin()
assert read_only(p, 'name') == 'Plugin' assert read_only(p, 'name') == 'Plugin'