[Python-checkins] CVS: python/dist/src/Lib/test test_binop.py,1.4,1.5 test_descr.py,1.31,1.32 test_descrtut.py,1.2,1.3
Guido van Rossum
gvanrossum@users.sourceforge.net
2001年9月06日 14:56:44 -0700
Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv13883
Modified Files:
test_binop.py test_descr.py test_descrtut.py
Log Message:
Rename 'getset' to 'property'.
Index: test_binop.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_binop.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** test_binop.py 2001年09月04日 19:14:14 1.4
--- test_binop.py 2001年09月06日 21:56:42 1.5
***************
*** 49,58 ****
"""Accessor function for read-only 'num' attribute of Rat."""
return self.__num
! num = getset(_get_num, None)
def _get_den(self):
"""Accessor function for read-only 'den' attribute of Rat."""
return self.__den
! den = getset(_get_den, None)
def __repr__(self):
--- 49,58 ----
"""Accessor function for read-only 'num' attribute of Rat."""
return self.__num
! num = property(_get_num, None)
def _get_den(self):
"""Accessor function for read-only 'den' attribute of Rat."""
return self.__den
! den = property(_get_den, None)
def __repr__(self):
Index: test_descr.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_descr.py,v
retrieving revision 1.31
retrieving revision 1.32
diff -C2 -d -r1.31 -r1.32
*** test_descr.py 2001年09月04日 01:20:04 1.31
--- test_descr.py 2001年09月06日 21:56:42 1.32
***************
*** 579,584 ****
verify(E().meth() == "EBCA")
! class autogetset(type):
! # Automatically create getset attributes when methods
# named _get_x and/or _set_x are found
def __new__(metaclass, name, bases, dict):
--- 579,584 ----
verify(E().meth() == "EBCA")
! class autoproperty(type):
! # Automatically create property attributes when methods
# named _get_x and/or _set_x are found
def __new__(metaclass, name, bases, dict):
***************
*** 596,604 ****
hits[key] = get, set
for key, (get, set) in hits.iteritems():
! dict[key] = getset(get, set)
! return super(autogetset, metaclass).__new__(metaclass,
name, bases, dict)
class A:
! __metaclass__ = autogetset
def _get_x(self):
return -self.__x
--- 596,604 ----
hits[key] = get, set
for key, (get, set) in hits.iteritems():
! dict[key] = property(get, set)
! return super(autoproperty, metaclass).__new__(metaclass,
name, bases, dict)
class A:
! __metaclass__ = autoproperty
def _get_x(self):
return -self.__x
***************
*** 611,615 ****
verify(a._A__x == -12)
! class multimetaclass(autogetset, autosuper):
# Merge of multiple cooperating metaclasses
pass
--- 611,615 ----
verify(a._A__x == -12)
! class multimetaclass(autoproperty, autosuper):
# Merge of multiple cooperating metaclasses
pass
***************
*** 1275,1280 ****
del r
! def getsets():
! if verbose: print "Testing getset..."
class C(object):
def getx(self):
--- 1275,1280 ----
del r
! def properties():
! if verbose: print "Testing property..."
class C(object):
def getx(self):
***************
*** 1284,1288 ****
def delx(self):
del self.__x
! x = getset(getx, setx, delx)
a = C()
verify(not hasattr(a, "x"))
--- 1284,1288 ----
def delx(self):
del self.__x
! x = property(getx, setx, delx)
a = C()
verify(not hasattr(a, "x"))
***************
*** 1446,1450 ****
specials()
weakrefs()
! getsets()
supers()
inherits()
--- 1446,1450 ----
specials()
weakrefs()
! properties()
supers()
inherits()
Index: test_descrtut.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_descrtut.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** test_descrtut.py 2001年09月03日 05:47:38 1.2
--- test_descrtut.py 2001年09月06日 21:56:42 1.3
***************
*** 316,320 ****
! >>> class getset(object):
...
... def __init__(self, get, set=None):
--- 316,320 ----
! >>> class property(object):
...
... def __init__(self, get, set=None):
***************
*** 345,349 ****
... self.__x = x
...
! ... x = getset(getx, setx)
Here's a small demonstration:
--- 345,349 ----
... self.__x = x
...
! ... x = property(getx, setx)
Here's a small demonstration:
***************
*** 358,366 ****
>>>
! Hmm -- getset is builtin now, so let's try it that way too.
! >>> del getset # unmask the builtin
! >>> getset
! <type 'getset'>
>>> class C(object):
--- 358,366 ----
>>>
! Hmm -- property is builtin now, so let's try it that way too.
! >>> del property # unmask the builtin
! >>> property
! <type 'property'>
>>> class C(object):
***************
*** 372,376 ****
... if x < 0: x = 0
... self.__x = x
! ... x = getset(getx, setx)
--- 372,376 ----
... if x < 0: x = 0
... self.__x = x
! ... x = property(getx, setx)