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
6661be3b
Kaydet (Commit)
6661be3b
authored
Eki 26, 2001
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Allow assignment to newinstance.__dict__.
üst
0afde13b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
1 deletion
+50
-1
test_descr.py
Lib/test/test_descr.py
+26
-0
typeobject.c
Objects/typeobject.c
+24
-1
No files found.
Lib/test/test_descr.py
Dosyayı görüntüle @
6661be3b
...
@@ -2084,6 +2084,31 @@ def setclass():
...
@@ -2084,6 +2084,31 @@ def setclass():
cant
(
object
(),
list
)
cant
(
object
(),
list
)
cant
(
list
(),
object
)
cant
(
list
(),
object
)
def
setdict
():
if
verbose
:
print
"Testing __dict__ assignment..."
class
C
(
object
):
pass
a
=
C
()
a
.
__dict__
=
{
'b'
:
1
}
vereq
(
a
.
b
,
1
)
def
cant
(
x
,
dict
):
try
:
x
.
__dict__
=
dict
except
TypeError
:
pass
else
:
raise
TestFailed
,
"shouldn't allow
%
r.__dict__ =
%
r"
%
(
x
,
dict
)
cant
(
a
,
None
)
cant
(
a
,
[])
cant
(
a
,
1
)
try
:
del
a
.
__dict__
except
TypeError
:
pass
else
:
raise
TestFailed
,
"shouldn't allow del
%
r.__dict__"
%
(
a
)
# Classes don't allow __dict__ assignment
cant
(
C
,
{})
def
pickles
():
def
pickles
():
if
verbose
:
if
verbose
:
print
"Testing pickling and copying new-style classes and objects..."
print
"Testing pickling and copying new-style classes and objects..."
...
@@ -2391,6 +2416,7 @@ def test_main():
...
@@ -2391,6 +2416,7 @@ def test_main():
coercions
()
coercions
()
descrdoc
()
descrdoc
()
setclass
()
setclass
()
setdict
()
pickles
()
pickles
()
copies
()
copies
()
binopoverride
()
binopoverride
()
...
...
Objects/typeobject.c
Dosyayı görüntüle @
6661be3b
...
@@ -674,8 +674,31 @@ subtype_dict(PyObject *obj, void *context)
...
@@ -674,8 +674,31 @@ subtype_dict(PyObject *obj, void *context)
return
dict
;
return
dict
;
}
}
static
int
subtype_setdict
(
PyObject
*
obj
,
PyObject
*
value
,
void
*
context
)
{
PyObject
**
dictptr
=
_PyObject_GetDictPtr
(
obj
);
PyObject
*
dict
;
if
(
dictptr
==
NULL
)
{
PyErr_SetString
(
PyExc_AttributeError
,
"This object has no __dict__"
);
return
-
1
;
}
if
(
value
==
NULL
||
!
PyDict_Check
(
value
))
{
PyErr_SetString
(
PyExc_TypeError
,
"__dict__ must be set to a dictionary"
);
return
-
1
;
}
dict
=
*
dictptr
;
Py_INCREF
(
value
);
*
dictptr
=
value
;
Py_XDECREF
(
dict
);
return
0
;
}
static
PyGetSetDef
subtype_getsets
[]
=
{
static
PyGetSetDef
subtype_getsets
[]
=
{
{
"__dict__"
,
subtype_dict
,
NULL
,
NULL
},
{
"__dict__"
,
subtype_dict
,
subtype_setdict
,
NULL
},
{
0
},
{
0
},
};
};
...
...
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