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
c393ee85
Kaydet (Commit)
c393ee85
authored
Mar 08, 2017
tarafından
Xiang Zhang
Kaydeden (comit)
GitHub
Mar 08, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-24329: allow __qualname__ and __classcell__ in __slots__ (GH-495)
üst
d5d3249e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
5 deletions
+51
-5
test_descr.py
Lib/test/test_descr.py
+40
-0
typeobject.c
Objects/typeobject.c
+11
-5
No files found.
Lib/test/test_descr.py
Dosyayı görüntüle @
c393ee85
...
...
@@ -1322,6 +1322,46 @@ order (MRO) for bases """
a
.
foo
=
42
self
.
assertEqual
(
a
.
__dict__
,
{
"foo"
:
42
})
def
test_slots_special2
(
self
):
# Testing __qualname__ and __classcell__ in __slots__
class
Meta
(
type
):
def
__new__
(
cls
,
name
,
bases
,
namespace
,
attr
):
self
.
assertIn
(
attr
,
namespace
)
return
super
()
.
__new__
(
cls
,
name
,
bases
,
namespace
)
class
C1
:
def
__init__
(
self
):
self
.
b
=
42
class
C2
(
C1
,
metaclass
=
Meta
,
attr
=
"__classcell__"
):
__slots__
=
[
"__classcell__"
]
def
__init__
(
self
):
super
()
.
__init__
()
self
.
assertIsInstance
(
C2
.
__dict__
[
"__classcell__"
],
types
.
MemberDescriptorType
)
c
=
C2
()
self
.
assertEqual
(
c
.
b
,
42
)
self
.
assertNotHasAttr
(
c
,
"__classcell__"
)
c
.
__classcell__
=
42
self
.
assertEqual
(
c
.
__classcell__
,
42
)
with
self
.
assertRaises
(
TypeError
):
class
C3
:
__classcell__
=
42
__slots__
=
[
"__classcell__"
]
class
Q1
(
metaclass
=
Meta
,
attr
=
"__qualname__"
):
__slots__
=
[
"__qualname__"
]
self
.
assertEqual
(
Q1
.
__qualname__
,
C1
.
__qualname__
[:
-
2
]
+
"Q1"
)
self
.
assertIsInstance
(
Q1
.
__dict__
[
"__qualname__"
],
types
.
MemberDescriptorType
)
q
=
Q1
()
self
.
assertNotHasAttr
(
q
,
"__qualname__"
)
q
.
__qualname__
=
"q"
self
.
assertEqual
(
q
.
__qualname__
,
"q"
)
with
self
.
assertRaises
(
TypeError
):
class
Q2
:
__qualname__
=
object
()
__slots__
=
[
"__qualname__"
]
def
test_slots_descriptor
(
self
):
# Issue2115: slot descriptors did not correctly check
# the type of the given object
...
...
Objects/typeobject.c
Dosyayı görüntüle @
c393ee85
...
...
@@ -2478,11 +2478,17 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
}
PyList_SET_ITEM
(
newslots
,
j
,
tmp
);
if
(
PyDict_GetItem
(
dict
,
tmp
))
{
PyErr_Format
(
PyExc_ValueError
,
"%R in __slots__ conflicts with class variable"
,
tmp
);
Py_DECREF
(
newslots
);
goto
error
;
/* CPython inserts __qualname__ and __classcell__ (when needed)
into the namespace when creating a class. They will be deleted
below so won't act as class variables. */
if
(
!
_PyUnicode_EqualToASCIIId
(
tmp
,
&
PyId___qualname__
)
&&
!
_PyUnicode_EqualToASCIIId
(
tmp
,
&
PyId___classcell__
))
{
PyErr_Format
(
PyExc_ValueError
,
"%R in __slots__ conflicts with class variable"
,
tmp
);
Py_DECREF
(
newslots
);
goto
error
;
}
}
j
++
;
}
...
...
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