Skip to content

Commit 8bce4ac

Browse files
committed
Rename 'getset' to 'property'.
1 parent 2872e8a commit 8bce4ac

6 files changed

Lines changed: 45 additions & 45 deletions

File tree

Include/descrobject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ extern DL_IMPORT(PyObject *) PyDictProxy_New(PyObject *);
3232
extern DL_IMPORT(PyObject *) PyWrapper_New(PyObject *, PyObject *);
3333

3434

35-
extern DL_IMPORT(PyTypeObject) PyGetSet_Type;
35+
extern DL_IMPORT(PyTypeObject) PyProperty_Type;

Lib/test/test_binop.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ def __init__(self, num=0L, den=1L):
4848
def _get_num(self):
4949
"""Accessor function for read-only 'num' attribute of Rat."""
5050
return self.__num
51-
num = getset(_get_num, None)
51+
num = property(_get_num, None)
5252

5353
def _get_den(self):
5454
"""Accessor function for read-only 'den' attribute of Rat."""
5555
return self.__den
56-
den = getset(_get_den, None)
56+
den = property(_get_den, None)
5757

5858
def __repr__(self):
5959
"""Convert a Rat to an string resembling a Rat constructor call."""

Lib/test/test_descr.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,8 @@ def meth(self):
578578
return "E" + self.__super.meth()
579579
verify(E().meth() == "EBCA")
580580

581-
class autogetset(type):
582-
# Automatically create getset attributes when methods
581+
class autoproperty(type):
582+
# Automatically create property attributes when methods
583583
# named _get_x and/or _set_x are found
584584
def __new__(metaclass, name, bases, dict):
585585
hits = {}
@@ -595,11 +595,11 @@ def __new__(metaclass, name, bases, dict):
595595
set = val
596596
hits[key] = get, set
597597
for key, (get, set) in hits.iteritems():
598-
dict[key] = getset(get, set)
599-
return super(autogetset, metaclass).__new__(metaclass,
598+
dict[key] = property(get, set)
599+
return super(autoproperty, metaclass).__new__(metaclass,
600600
name, bases, dict)
601601
class A:
602-
__metaclass__ = autogetset
602+
__metaclass__ = autoproperty
603603
def _get_x(self):
604604
return -self.__x
605605
def _set_x(self, x):
@@ -610,7 +610,7 @@ def _set_x(self, x):
610610
verify(a.x == 12)
611611
verify(a._A__x == -12)
612612

613-
class multimetaclass(autogetset, autosuper):
613+
class multimetaclass(autoproperty, autosuper):
614614
# Merge of multiple cooperating metaclasses
615615
pass
616616
class A:
@@ -1274,16 +1274,16 @@ class Weak(object):
12741274
verify(r() is None)
12751275
del r
12761276

1277-
def getsets():
1278-
if verbose: print "Testing getset..."
1277+
def properties():
1278+
if verbose: print "Testing property..."
12791279
class C(object):
12801280
def getx(self):
12811281
return self.__x
12821282
def setx(self, value):
12831283
self.__x = value
12841284
def delx(self):
12851285
del self.__x
1286-
x = getset(getx, setx, delx)
1286+
x = property(getx, setx, delx)
12871287
a = C()
12881288
verify(not hasattr(a, "x"))
12891289
a.x = 42
@@ -1445,7 +1445,7 @@ def all():
14451445
methods()
14461446
specials()
14471447
weakrefs()
1448-
getsets()
1448+
properties()
14491449
supers()
14501450
inherits()
14511451

Lib/test/test_descrtut.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ class passed as the first argument of foo() is the class involved in the
315315
Attributes defined by get/set methods
316316
317317
318-
>>> class getset(object):
318+
>>> class property(object):
319319
...
320320
... def __init__(self, get, set=None):
321321
... self.__get = get
@@ -344,7 +344,7 @@ class passed as the first argument of foo() is the class involved in the
344344
... if x < 0: x = 0
345345
... self.__x = x
346346
...
347-
... x = getset(getx, setx)
347+
... x = property(getx, setx)
348348
349349
Here's a small demonstration:
350350
@@ -357,11 +357,11 @@ class passed as the first argument of foo() is the class involved in the
357357
0
358358
>>>
359359
360-
Hmm -- getset is builtin now, so let's try it that way too.
360+
Hmm -- property is builtin now, so let's try it that way too.
361361
362-
>>> del getset # unmask the builtin
363-
>>> getset
364-
<type 'getset'>
362+
>>> del property # unmask the builtin
363+
>>> property
364+
<type 'property'>
365365
366366
>>> class C(object):
367367
... def __init__(self):
@@ -371,7 +371,7 @@ class passed as the first argument of foo() is the class involved in the
371371
... def setx(self, x):
372372
... if x < 0: x = 0
373373
... self.__x = x
374-
... x = getset(getx, setx)
374+
... x = property(getx, setx)
375375
376376
377377
>>> a = C()

Objects/descrobject.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -840,10 +840,10 @@ PyWrapper_New(PyObject *d, PyObject *self)
840840
}
841841

842842

843-
/* A built-in 'getset' type */
843+
/* A built-in 'property' type */
844844

845845
/*
846-
class getset(object):
846+
class property(object):
847847
848848
def __init__(self, get=None, set=None):
849849
self.__get = get
@@ -867,12 +867,12 @@ typedef struct {
867867
PyObject *get;
868868
PyObject *set;
869869
PyObject *del;
870-
} getsetobject;
870+
} propertyobject;
871871

872872
static void
873-
getset_dealloc(PyObject *self)
873+
property_dealloc(PyObject *self)
874874
{
875-
getsetobject *gs = (getsetobject *)self;
875+
propertyobject *gs = (propertyobject *)self;
876876

877877
Py_XDECREF(gs->get);
878878
Py_XDECREF(gs->set);
@@ -881,9 +881,9 @@ getset_dealloc(PyObject *self)
881881
}
882882

883883
static PyObject *
884-
getset_descr_get(PyObject *self, PyObject *obj, PyObject *type)
884+
property_descr_get(PyObject *self, PyObject *obj, PyObject *type)
885885
{
886-
getsetobject *gs = (getsetobject *)self;
886+
propertyobject *gs = (propertyobject *)self;
887887

888888
if (gs->get == NULL) {
889889
PyErr_SetString(PyExc_AttributeError, "unreadable attribute");
@@ -897,9 +897,9 @@ getset_descr_get(PyObject *self, PyObject *obj, PyObject *type)
897897
}
898898

899899
static int
900-
getset_descr_set(PyObject *self, PyObject *obj, PyObject *value)
900+
property_descr_set(PyObject *self, PyObject *obj, PyObject *value)
901901
{
902-
getsetobject *gs = (getsetobject *)self;
902+
propertyobject *gs = (propertyobject *)self;
903903
PyObject *func, *res;
904904

905905
if (value == NULL)
@@ -924,12 +924,12 @@ getset_descr_set(PyObject *self, PyObject *obj, PyObject *value)
924924
}
925925

926926
static int
927-
getset_init(PyObject *self, PyObject *args, PyObject *kwds)
927+
property_init(PyObject *self, PyObject *args, PyObject *kwds)
928928
{
929929
PyObject *get = NULL, *set = NULL, *del = NULL;
930-
getsetobject *gs = (getsetobject *)self;
930+
propertyobject *gs = (propertyobject *)self;
931931

932-
if (!PyArg_ParseTuple(args, "|OOO:getset", &get, &set, &del))
932+
if (!PyArg_ParseTuple(args, "|OOO:property", &get, &set, &del))
933933
return -1;
934934
if (get == Py_None)
935935
get = NULL;
@@ -944,23 +944,23 @@ getset_init(PyObject *self, PyObject *args, PyObject *kwds)
944944
return 0;
945945
}
946946

947-
static char getset_doc[] =
948-
"getset([getfunc[, setfunc[, delfunc]]]) -> getset attribute\n"
947+
static char property_doc[] =
948+
"property([getfunc[, setfunc[, delfunc]]]) -> property attribute\n"
949949
"Typical use to define a managed attribute x of C instances:\n"
950950
"class C(object):\n"
951951
" def getx(self): return self.__x\n"
952952
" def setx(self, value): self.__x = value\n"
953953
" def delx(self): del self.__x\n"
954-
" x = getset(getx, setx, delx)";
954+
" x = property(getx, setx, delx)";
955955

956-
PyTypeObject PyGetSet_Type = {
956+
PyTypeObject PyProperty_Type = {
957957
PyObject_HEAD_INIT(&PyType_Type)
958958
0, /* ob_size */
959-
"getset", /* tp_name */
960-
sizeof(getsetobject), /* tp_basicsize */
959+
"property", /* tp_name */
960+
sizeof(propertyobject), /* tp_basicsize */
961961
0, /* tp_itemsize */
962962
/* methods */
963-
getset_dealloc, /* tp_dealloc */
963+
property_dealloc, /* tp_dealloc */
964964
0, /* tp_print */
965965
0, /* tp_getattr */
966966
0, /* tp_setattr */
@@ -976,7 +976,7 @@ PyTypeObject PyGetSet_Type = {
976976
0, /* tp_setattro */
977977
0, /* tp_as_buffer */
978978
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
979-
getset_doc, /* tp_doc */
979+
property_doc, /* tp_doc */
980980
0, /* tp_traverse */
981981
0, /* tp_clear */
982982
0, /* tp_richcompare */
@@ -988,10 +988,10 @@ PyTypeObject PyGetSet_Type = {
988988
0, /* tp_getset */
989989
0, /* tp_base */
990990
0, /* tp_dict */
991-
getset_descr_get, /* tp_descr_get */
992-
getset_descr_set, /* tp_descr_set */
991+
property_descr_get, /* tp_descr_get */
992+
property_descr_set, /* tp_descr_set */
993993
0, /* tp_dictoffset */
994-
getset_init, /* tp_init */
994+
property_init, /* tp_init */
995995
PyType_GenericAlloc, /* tp_alloc */
996996
PyType_GenericNew, /* tp_new */
997997
_PyObject_Del, /* tp_free */

Python/bltinmodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,8 +1869,8 @@ _PyBuiltin_Init(void)
18691869
if (PyDict_SetItemString(dict, "float",
18701870
(PyObject *) &PyFloat_Type) < 0)
18711871
return NULL;
1872-
if (PyDict_SetItemString(dict, "getset",
1873-
(PyObject *) &PyGetSet_Type) < 0)
1872+
if (PyDict_SetItemString(dict, "property",
1873+
(PyObject *) &PyProperty_Type) < 0)
18741874
return NULL;
18751875
if (PyDict_SetItemString(dict, "int", (PyObject *) &PyInt_Type) < 0)
18761876
return NULL;

0 commit comments

Comments
 (0)