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
9d57481f
Kaydet (Commit)
9d57481f
authored
Ara 12, 2011
tarafından
Antoine Pitrou
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #13577: various kinds of descriptors now have a __qualname__ attribute.
Patch by sbt.
üst
16e6a809
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
74 additions
and
4 deletions
+74
-4
descrobject.h
Include/descrobject.h
+1
-0
test_descr.py
Lib/test/test_descr.py
+18
-0
test_sys.py
Lib/test/test_sys.py
+4
-4
descrobject.c
Objects/descrobject.c
+51
-0
No files found.
Include/descrobject.h
Dosyayı görüntüle @
9d57481f
...
...
@@ -42,6 +42,7 @@ typedef struct {
PyObject_HEAD
PyTypeObject
*
d_type
;
PyObject
*
d_name
;
PyObject
*
d_qualname
;
}
PyDescrObject
;
#define PyDescr_COMMON PyDescrObject d_common
...
...
Lib/test/test_descr.py
Dosyayı görüntüle @
9d57481f
...
...
@@ -4442,6 +4442,24 @@ order (MRO) for bases """
self
.
assertIn
(
"can't delete X.__doc__"
,
str
(
cm
.
exception
))
self
.
assertEqual
(
X
.
__doc__
,
"banana"
)
def
test_qualname
(
self
):
descriptors
=
[
str
.
lower
,
complex
.
real
,
float
.
real
,
int
.
__add__
]
types
=
[
'method'
,
'member'
,
'getset'
,
'wrapper'
]
# make sure we have an example of each type of descriptor
for
d
,
n
in
zip
(
descriptors
,
types
):
self
.
assertEqual
(
type
(
d
)
.
__name__
,
n
+
'_descriptor'
)
for
d
in
descriptors
:
qualname
=
d
.
__objclass__
.
__qualname__
+
'.'
+
d
.
__name__
self
.
assertEqual
(
d
.
__qualname__
,
qualname
)
self
.
assertEqual
(
str
.
lower
.
__qualname__
,
'str.lower'
)
self
.
assertEqual
(
complex
.
real
.
__qualname__
,
'complex.real'
)
self
.
assertEqual
(
float
.
real
.
__qualname__
,
'float.real'
)
self
.
assertEqual
(
int
.
__add__
.
__qualname__
,
'int.__add__'
)
class
DictProxyTests
(
unittest
.
TestCase
):
def
setUp
(
self
):
class
C
(
object
):
...
...
Lib/test/test_sys.py
Dosyayı görüntüle @
9d57481f
...
...
@@ -670,17 +670,17 @@ class SizeofTest(unittest.TestCase):
# complex
check
(
complex
(
0
,
1
),
size
(
h
+
'2d'
))
# method_descriptor (descriptor object)
check
(
str
.
lower
,
size
(
h
+
'
2
PP'
))
check
(
str
.
lower
,
size
(
h
+
'
3
PP'
))
# classmethod_descriptor (descriptor object)
# XXX
# member_descriptor (descriptor object)
import
datetime
check
(
datetime
.
timedelta
.
days
,
size
(
h
+
'
2
PP'
))
check
(
datetime
.
timedelta
.
days
,
size
(
h
+
'
3
PP'
))
# getset_descriptor (descriptor object)
import
collections
check
(
collections
.
defaultdict
.
default_factory
,
size
(
h
+
'
2
PP'
))
check
(
collections
.
defaultdict
.
default_factory
,
size
(
h
+
'
3
PP'
))
# wrapper_descriptor (descriptor object)
check
(
int
.
__add__
,
size
(
h
+
'
2
P2P'
))
check
(
int
.
__add__
,
size
(
h
+
'
3
P2P'
))
# method-wrapper (descriptor object)
check
({}
.
__iter__
,
size
(
h
+
'2P'
))
# dict
...
...
Objects/descrobject.c
Dosyayı görüntüle @
9d57481f
...
...
@@ -9,6 +9,7 @@ descr_dealloc(PyDescrObject *descr)
_PyObject_GC_UNTRACK
(
descr
);
Py_XDECREF
(
descr
->
d_type
);
Py_XDECREF
(
descr
->
d_name
);
Py_XDECREF
(
descr
->
d_qualname
);
PyObject_GC_Del
(
descr
);
}
...
...
@@ -321,6 +322,44 @@ method_get_doc(PyMethodDescrObject *descr, void *closure)
return
PyUnicode_FromString
(
descr
->
d_method
->
ml_doc
);
}
static
PyObject
*
calculate_qualname
(
PyDescrObject
*
descr
)
{
PyObject
*
type_qualname
,
*
res
;
_Py_IDENTIFIER
(
__qualname__
);
if
(
descr
->
d_name
==
NULL
||
!
PyUnicode_Check
(
descr
->
d_name
))
{
PyErr_SetString
(
PyExc_TypeError
,
"<descriptor>.__name__ is not a unicode object"
);
return
NULL
;
}
type_qualname
=
_PyObject_GetAttrId
((
PyObject
*
)
descr
->
d_type
,
&
PyId___qualname__
);
if
(
type_qualname
==
NULL
)
return
NULL
;
if
(
!
PyUnicode_Check
(
type_qualname
))
{
PyErr_SetString
(
PyExc_TypeError
,
"<descriptor>.__objclass__."
"__qualname__ is not a unicode object"
);
Py_XDECREF
(
type_qualname
);
return
NULL
;
}
res
=
PyUnicode_FromFormat
(
"%S.%S"
,
type_qualname
,
descr
->
d_name
);
Py_DECREF
(
type_qualname
);
return
res
;
}
static
PyObject
*
descr_get_qualname
(
PyDescrObject
*
descr
)
{
if
(
descr
->
d_qualname
==
NULL
)
descr
->
d_qualname
=
calculate_qualname
(
descr
);
Py_XINCREF
(
descr
->
d_qualname
);
return
descr
->
d_qualname
;
}
static
PyMemberDef
descr_members
[]
=
{
{
"__objclass__"
,
T_OBJECT
,
offsetof
(
PyDescrObject
,
d_type
),
READONLY
},
{
"__name__"
,
T_OBJECT
,
offsetof
(
PyDescrObject
,
d_name
),
READONLY
},
...
...
@@ -329,6 +368,7 @@ static PyMemberDef descr_members[] = {
static
PyGetSetDef
method_getset
[]
=
{
{
"__doc__"
,
(
getter
)
method_get_doc
},
{
"__qualname__"
,
(
getter
)
descr_get_qualname
},
{
0
}
};
...
...
@@ -344,6 +384,7 @@ member_get_doc(PyMemberDescrObject *descr, void *closure)
static
PyGetSetDef
member_getset
[]
=
{
{
"__doc__"
,
(
getter
)
member_get_doc
},
{
"__qualname__"
,
(
getter
)
descr_get_qualname
},
{
0
}
};
...
...
@@ -359,6 +400,7 @@ getset_get_doc(PyGetSetDescrObject *descr, void *closure)
static
PyGetSetDef
getset_getset
[]
=
{
{
"__doc__"
,
(
getter
)
getset_get_doc
},
{
"__qualname__"
,
(
getter
)
descr_get_qualname
},
{
0
}
};
...
...
@@ -374,6 +416,7 @@ wrapperdescr_get_doc(PyWrapperDescrObject *descr, void *closure)
static
PyGetSetDef
wrapperdescr_getset
[]
=
{
{
"__doc__"
,
(
getter
)
wrapperdescr_get_doc
},
{
"__qualname__"
,
(
getter
)
descr_get_qualname
},
{
0
}
};
...
...
@@ -585,6 +628,7 @@ descr_new(PyTypeObject *descrtype, PyTypeObject *type, const char *name)
Py_DECREF
(
descr
);
descr
=
NULL
;
}
descr
->
d_qualname
=
NULL
;
}
return
descr
;
}
...
...
@@ -987,9 +1031,16 @@ wrapper_doc(wrapperobject *wp)
}
}
static
PyObject
*
wrapper_qualname
(
wrapperobject
*
wp
)
{
return
descr_get_qualname
((
PyDescrObject
*
)
wp
->
descr
);
}
static
PyGetSetDef
wrapper_getsets
[]
=
{
{
"__objclass__"
,
(
getter
)
wrapper_objclass
},
{
"__name__"
,
(
getter
)
wrapper_name
},
{
"__qualname__"
,
(
getter
)
wrapper_qualname
},
{
"__doc__"
,
(
getter
)
wrapper_doc
},
{
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