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
e686c5c3
Kaydet (Commit)
e686c5c3
authored
Şub 16, 2014
tarafından
Benjamin Peterson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
look up __getnewargs__ and __getnewargs_ex__ on the object type (#16251)
üst
1bcfbd51
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
12 deletions
+23
-12
test_descr.py
Lib/test/test_descr.py
+14
-0
NEWS
Misc/NEWS
+3
-0
typeobject.c
Objects/typeobject.c
+6
-12
No files found.
Lib/test/test_descr.py
Dosyayı görüntüle @
e686c5c3
...
...
@@ -4701,6 +4701,20 @@ class PicklingTests(unittest.TestCase):
for
proto
in
protocols
:
self
.
_check_reduce
(
proto
,
obj
,
listitems
=
list
(
obj
))
def
test_special_method_lookup
(
self
):
protocols
=
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
)
class
Picky
:
def
__getstate__
(
self
):
return
{}
def
__getattr__
(
self
,
attr
):
if
attr
in
(
"__getnewargs__"
,
"__getnewargs_ex__"
):
raise
AssertionError
(
attr
)
return
None
for
protocol
in
protocols
:
state
=
{}
if
protocol
>=
2
else
None
self
.
_check_reduce
(
protocol
,
Picky
(),
state
=
state
)
def
_assert_is_copy
(
self
,
obj
,
objcopy
,
msg
=
None
):
"""Utility method to verify if two objects are copies of each others.
"""
...
...
Misc/NEWS
Dosyayı görüntüle @
e686c5c3
...
...
@@ -10,6 +10,9 @@ Release date: 2014-02-23
Core and Builtins
-----------------
- Issue #20261: In pickle, lookup __getnewargs__ and __getnewargs_ex__ on the
type of the object.
- Issue #20619: Give the AST nodes of keyword-only arguments a column and line
number.
...
...
Objects/typeobject.c
Dosyayı görüntüle @
e686c5c3
...
...
@@ -3719,7 +3719,7 @@ _PyObject_GetNewArguments(PyObject *obj, PyObject **args, PyObject **kwargs)
/* We first attempt to fetch the arguments for __new__ by calling
__getnewargs_ex__ on the object. */
getnewargs_ex
=
_PyObject_
GetAttrId
(
obj
,
&
PyId___getnewargs_ex__
);
getnewargs_ex
=
_PyObject_
LookupSpecial
(
obj
,
&
PyId___getnewargs_ex__
);
if
(
getnewargs_ex
!=
NULL
)
{
PyObject
*
newargs
=
PyObject_CallObject
(
getnewargs_ex
,
NULL
);
Py_DECREF
(
getnewargs_ex
);
...
...
@@ -3766,16 +3766,13 @@ _PyObject_GetNewArguments(PyObject *obj, PyObject **args, PyObject **kwargs)
return
-
1
;
}
return
0
;
}
else
{
if
(
!
PyErr_ExceptionMatches
(
PyExc_AttributeError
))
{
return
-
1
;
}
PyErr_Clear
();
}
else
if
(
PyErr_Occurred
())
{
return
-
1
;
}
/* The object does not have __getnewargs_ex__ so we fallback on using
__getnewargs__ instead. */
getnewargs
=
_PyObject_
GetAttrId
(
obj
,
&
PyId___getnewargs__
);
getnewargs
=
_PyObject_
LookupSpecial
(
obj
,
&
PyId___getnewargs__
);
if
(
getnewargs
!=
NULL
)
{
*
args
=
PyObject_CallObject
(
getnewargs
,
NULL
);
Py_DECREF
(
getnewargs
);
...
...
@@ -3791,11 +3788,8 @@ _PyObject_GetNewArguments(PyObject *obj, PyObject **args, PyObject **kwargs)
}
*
kwargs
=
NULL
;
return
0
;
}
else
{
if
(
!
PyErr_ExceptionMatches
(
PyExc_AttributeError
))
{
return
-
1
;
}
PyErr_Clear
();
}
else
if
(
PyErr_Occurred
())
{
return
-
1
;
}
/* The object does not have __getnewargs_ex__ and __getnewargs__. This may
...
...
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