Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
8bce4acb
Kaydet (Commit)
8bce4acb
authored
Eyl 06, 2001
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Rename 'getset' to 'property'.
üst
2872e8a6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
45 additions
and
45 deletions
+45
-45
descrobject.h
Include/descrobject.h
+1
-1
test_binop.py
Lib/test/test_binop.py
+2
-2
test_descr.py
Lib/test/test_descr.py
+10
-10
test_descrtut.py
Lib/test/test_descrtut.py
+7
-7
descrobject.c
Objects/descrobject.c
+23
-23
bltinmodule.c
Python/bltinmodule.c
+2
-2
No files found.
Include/descrobject.h
Dosyayı görüntüle @
8bce4acb
...
...
@@ -32,4 +32,4 @@ extern DL_IMPORT(PyObject *) PyDictProxy_New(PyObject *);
extern
DL_IMPORT
(
PyObject
*
)
PyWrapper_New
(
PyObject
*
,
PyObject
*
);
extern
DL_IMPORT
(
PyTypeObject
)
Py
GetSet
_Type
;
extern
DL_IMPORT
(
PyTypeObject
)
Py
Property
_Type
;
Lib/test/test_binop.py
Dosyayı görüntüle @
8bce4acb
...
...
@@ -48,12 +48,12 @@ class Rat(object):
def
_get_num
(
self
):
"""Accessor function for read-only 'num' attribute of Rat."""
return
self
.
__num
num
=
getset
(
_get_num
,
None
)
num
=
property
(
_get_num
,
None
)
def
_get_den
(
self
):
"""Accessor function for read-only 'den' attribute of Rat."""
return
self
.
__den
den
=
getset
(
_get_den
,
None
)
den
=
property
(
_get_den
,
None
)
def
__repr__
(
self
):
"""Convert a Rat to an string resembling a Rat constructor call."""
...
...
Lib/test/test_descr.py
Dosyayı görüntüle @
8bce4acb
...
...
@@ -578,8 +578,8 @@ def metaclass():
return
"E"
+
self
.
__super
.
meth
()
verify
(
E
()
.
meth
()
==
"EBCA"
)
class
auto
getset
(
type
):
# Automatically create
getset
attributes when methods
class
auto
property
(
type
):
# Automatically create
property
attributes when methods
# named _get_x and/or _set_x are found
def
__new__
(
metaclass
,
name
,
bases
,
dict
):
hits
=
{}
...
...
@@ -595,11 +595,11 @@ def metaclass():
set
=
val
hits
[
key
]
=
get
,
set
for
key
,
(
get
,
set
)
in
hits
.
iteritems
():
dict
[
key
]
=
getset
(
get
,
set
)
return
super
(
auto
getset
,
metaclass
)
.
__new__
(
metaclass
,
dict
[
key
]
=
property
(
get
,
set
)
return
super
(
auto
property
,
metaclass
)
.
__new__
(
metaclass
,
name
,
bases
,
dict
)
class
A
:
__metaclass__
=
auto
getset
__metaclass__
=
auto
property
def
_get_x
(
self
):
return
-
self
.
__x
def
_set_x
(
self
,
x
):
...
...
@@ -610,7 +610,7 @@ def metaclass():
verify
(
a
.
x
==
12
)
verify
(
a
.
_A__x
==
-
12
)
class
multimetaclass
(
auto
getset
,
autosuper
):
class
multimetaclass
(
auto
property
,
autosuper
):
# Merge of multiple cooperating metaclasses
pass
class
A
:
...
...
@@ -1274,8 +1274,8 @@ def weakrefs():
verify
(
r
()
is
None
)
del
r
def
getset
s
():
if
verbose
:
print
"Testing
getset
..."
def
propertie
s
():
if
verbose
:
print
"Testing
property
..."
class
C
(
object
):
def
getx
(
self
):
return
self
.
__x
...
...
@@ -1283,7 +1283,7 @@ def getsets():
self
.
__x
=
value
def
delx
(
self
):
del
self
.
__x
x
=
getset
(
getx
,
setx
,
delx
)
x
=
property
(
getx
,
setx
,
delx
)
a
=
C
()
verify
(
not
hasattr
(
a
,
"x"
))
a
.
x
=
42
...
...
@@ -1445,7 +1445,7 @@ def all():
methods
()
specials
()
weakrefs
()
getset
s
()
propertie
s
()
supers
()
inherits
()
...
...
Lib/test/test_descrtut.py
Dosyayı görüntüle @
8bce4acb
...
...
@@ -315,7 +315,7 @@ test_5 = """
Attributes defined by get/set methods
>>> class
getset
(object):
>>> class
property
(object):
...
... def __init__(self, get, set=None):
... self.__get = get
...
...
@@ -344,7 +344,7 @@ getx() and and setx():
... if x < 0: x = 0
... self.__x = x
...
... x =
getset
(getx, setx)
... x =
property
(getx, setx)
Here's a small demonstration:
...
...
@@ -357,11 +357,11 @@ Here's a small demonstration:
0
>>>
Hmm --
getset
is builtin now, so let's try it that way too.
Hmm --
property
is builtin now, so let's try it that way too.
>>> del
getset
# unmask the builtin
>>>
getset
<type '
getset
'>
>>> del
property
# unmask the builtin
>>>
property
<type '
property
'>
>>> class C(object):
... def __init__(self):
...
...
@@ -371,7 +371,7 @@ Hmm -- getset is builtin now, so let's try it that way too.
... def setx(self, x):
... if x < 0: x = 0
... self.__x = x
... x =
getset
(getx, setx)
... x =
property
(getx, setx)
>>> a = C()
...
...
Objects/descrobject.c
Dosyayı görüntüle @
8bce4acb
...
...
@@ -840,10 +840,10 @@ PyWrapper_New(PyObject *d, PyObject *self)
}
/* A built-in '
getset
' type */
/* A built-in '
property
' type */
/*
class
getset
(object):
class
property
(object):
def __init__(self, get=None, set=None):
self.__get = get
...
...
@@ -867,12 +867,12 @@ typedef struct {
PyObject
*
get
;
PyObject
*
set
;
PyObject
*
del
;
}
getset
object
;
}
property
object
;
static
void
getset
_dealloc
(
PyObject
*
self
)
property
_dealloc
(
PyObject
*
self
)
{
getsetobject
*
gs
=
(
getset
object
*
)
self
;
propertyobject
*
gs
=
(
property
object
*
)
self
;
Py_XDECREF
(
gs
->
get
);
Py_XDECREF
(
gs
->
set
);
...
...
@@ -881,9 +881,9 @@ getset_dealloc(PyObject *self)
}
static
PyObject
*
getset
_descr_get
(
PyObject
*
self
,
PyObject
*
obj
,
PyObject
*
type
)
property
_descr_get
(
PyObject
*
self
,
PyObject
*
obj
,
PyObject
*
type
)
{
getsetobject
*
gs
=
(
getset
object
*
)
self
;
propertyobject
*
gs
=
(
property
object
*
)
self
;
if
(
gs
->
get
==
NULL
)
{
PyErr_SetString
(
PyExc_AttributeError
,
"unreadable attribute"
);
...
...
@@ -897,9 +897,9 @@ getset_descr_get(PyObject *self, PyObject *obj, PyObject *type)
}
static
int
getset
_descr_set
(
PyObject
*
self
,
PyObject
*
obj
,
PyObject
*
value
)
property
_descr_set
(
PyObject
*
self
,
PyObject
*
obj
,
PyObject
*
value
)
{
getsetobject
*
gs
=
(
getset
object
*
)
self
;
propertyobject
*
gs
=
(
property
object
*
)
self
;
PyObject
*
func
,
*
res
;
if
(
value
==
NULL
)
...
...
@@ -924,12 +924,12 @@ getset_descr_set(PyObject *self, PyObject *obj, PyObject *value)
}
static
int
getset
_init
(
PyObject
*
self
,
PyObject
*
args
,
PyObject
*
kwds
)
property
_init
(
PyObject
*
self
,
PyObject
*
args
,
PyObject
*
kwds
)
{
PyObject
*
get
=
NULL
,
*
set
=
NULL
,
*
del
=
NULL
;
getsetobject
*
gs
=
(
getset
object
*
)
self
;
propertyobject
*
gs
=
(
property
object
*
)
self
;
if
(
!
PyArg_ParseTuple
(
args
,
"|OOO:
getset
"
,
&
get
,
&
set
,
&
del
))
if
(
!
PyArg_ParseTuple
(
args
,
"|OOO:
property
"
,
&
get
,
&
set
,
&
del
))
return
-
1
;
if
(
get
==
Py_None
)
get
=
NULL
;
...
...
@@ -944,23 +944,23 @@ getset_init(PyObject *self, PyObject *args, PyObject *kwds)
return
0
;
}
static
char
getset
_doc
[]
=
"
getset([getfunc[, setfunc[, delfunc]]]) -> getset
attribute
\n
"
static
char
property
_doc
[]
=
"
property([getfunc[, setfunc[, delfunc]]]) -> property
attribute
\n
"
"Typical use to define a managed attribute x of C instances:
\n
"
"class C(object):
\n
"
" def getx(self): return self.__x
\n
"
" def setx(self, value): self.__x = value
\n
"
" def delx(self): del self.__x
\n
"
" x =
getset
(getx, setx, delx)"
;
" x =
property
(getx, setx, delx)"
;
PyTypeObject
Py
GetSet
_Type
=
{
PyTypeObject
Py
Property
_Type
=
{
PyObject_HEAD_INIT
(
&
PyType_Type
)
0
,
/* ob_size */
"
getset
"
,
/* tp_name */
sizeof
(
getset
object
),
/* tp_basicsize */
"
property
"
,
/* tp_name */
sizeof
(
property
object
),
/* tp_basicsize */
0
,
/* tp_itemsize */
/* methods */
getset_dealloc
,
/* tp_dealloc */
property_dealloc
,
/* tp_dealloc */
0
,
/* tp_print */
0
,
/* tp_getattr */
0
,
/* tp_setattr */
...
...
@@ -976,7 +976,7 @@ PyTypeObject PyGetSet_Type = {
0
,
/* tp_setattro */
0
,
/* tp_as_buffer */
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_BASETYPE
,
/* tp_flags */
getset
_doc
,
/* tp_doc */
property
_doc
,
/* tp_doc */
0
,
/* tp_traverse */
0
,
/* tp_clear */
0
,
/* tp_richcompare */
...
...
@@ -988,10 +988,10 @@ PyTypeObject PyGetSet_Type = {
0
,
/* tp_getset */
0
,
/* tp_base */
0
,
/* tp_dict */
getset
_descr_get
,
/* tp_descr_get */
getset
_descr_set
,
/* tp_descr_set */
property
_descr_get
,
/* tp_descr_get */
property
_descr_set
,
/* tp_descr_set */
0
,
/* tp_dictoffset */
getset
_init
,
/* tp_init */
property
_init
,
/* tp_init */
PyType_GenericAlloc
,
/* tp_alloc */
PyType_GenericNew
,
/* tp_new */
_PyObject_Del
,
/* tp_free */
...
...
Python/bltinmodule.c
Dosyayı görüntüle @
8bce4acb
...
...
@@ -1869,8 +1869,8 @@ _PyBuiltin_Init(void)
if
(
PyDict_SetItemString
(
dict
,
"float"
,
(
PyObject
*
)
&
PyFloat_Type
)
<
0
)
return
NULL
;
if
(
PyDict_SetItemString
(
dict
,
"
getset
"
,
(
PyObject
*
)
&
Py
GetSet
_Type
)
<
0
)
if
(
PyDict_SetItemString
(
dict
,
"
property
"
,
(
PyObject
*
)
&
Py
Property
_Type
)
<
0
)
return
NULL
;
if
(
PyDict_SetItemString
(
dict
,
"int"
,
(
PyObject
*
)
&
PyInt_Type
)
<
0
)
return
NULL
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment