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
e49af341
Kaydet (Commit)
e49af341
authored
Mar 01, 2015
tarafından
Alexander Belopolsky
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #7830: Flatten nested functools.partial.
üst
e2e178e0
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
7 deletions
+68
-7
functools.py
Lib/functools.py
+8
-0
test_functools.py
Lib/test/test_functools.py
+10
-0
NEWS
Misc/NEWS
+2
-0
_functoolsmodule.c
Modules/_functoolsmodule.c
+48
-7
No files found.
Lib/functools.py
Dosyayı görüntüle @
e49af341
...
...
@@ -241,6 +241,14 @@ def partial(func, *args, **keywords):
"""New function with partial application of the given arguments
and keywords.
"""
if
hasattr
(
func
,
'func'
):
args
=
func
.
args
+
args
tmpkw
=
func
.
keywords
.
copy
()
tmpkw
.
update
(
keywords
)
keywords
=
tmpkw
del
tmpkw
func
=
func
.
func
def
newfunc
(
*
fargs
,
**
fkeywords
):
newkeywords
=
keywords
.
copy
()
newkeywords
.
update
(
fkeywords
)
...
...
Lib/test/test_functools.py
Dosyayı görüntüle @
e49af341
...
...
@@ -131,6 +131,16 @@ class TestPartial:
join
=
self
.
partial
(
''
.
join
)
self
.
assertEqual
(
join
(
data
),
'0123456789'
)
def
test_nested_optimization
(
self
):
partial
=
self
.
partial
# Only "true" partial is optimized
if
partial
.
__name__
!=
'partial'
:
return
inner
=
partial
(
signature
,
'asdf'
)
nested
=
partial
(
inner
,
bar
=
True
)
flat
=
partial
(
signature
,
'asdf'
,
bar
=
True
)
self
.
assertEqual
(
signature
(
nested
),
signature
(
flat
))
@unittest.skipUnless
(
c_functools
,
'requires the C _functools module'
)
class
TestPartialC
(
TestPartial
,
unittest
.
TestCase
):
...
...
Misc/NEWS
Dosyayı görüntüle @
e49af341
...
...
@@ -13,6 +13,8 @@ Core and Builtins
Library
-------
- Issue #7830: Flatten nested functools.partial.
- Issue #20204: Added the __module__ attribute to _tkinter classes.
- Issue #19980: Improved help() for non-recognized strings. help('') now
...
...
Modules/_functoolsmodule.c
Dosyayı görüntüle @
e49af341
...
...
@@ -25,7 +25,7 @@ static PyTypeObject partial_type;
static
PyObject
*
partial_new
(
PyTypeObject
*
type
,
PyObject
*
args
,
PyObject
*
kw
)
{
PyObject
*
func
;
PyObject
*
func
,
*
pargs
,
*
nargs
,
*
pkw
;
partialobject
*
pto
;
if
(
PyTuple_GET_SIZE
(
args
)
<
1
)
{
...
...
@@ -34,7 +34,16 @@ partial_new(PyTypeObject *type, PyObject *args, PyObject *kw)
return
NULL
;
}
pargs
=
pkw
=
Py_None
;
func
=
PyTuple_GET_ITEM
(
args
,
0
);
if
(
Py_TYPE
(
func
)
==
&
partial_type
&&
type
==
&
partial_type
)
{
partialobject
*
part
=
(
partialobject
*
)
func
;
if
(
part
->
dict
==
NULL
)
{
pargs
=
part
->
args
;
pkw
=
part
->
kw
;
func
=
part
->
fn
;
}
}
if
(
!
PyCallable_Check
(
func
))
{
PyErr_SetString
(
PyExc_TypeError
,
"the first argument must be callable"
);
...
...
@@ -48,21 +57,53 @@ partial_new(PyTypeObject *type, PyObject *args, PyObject *kw)
pto
->
fn
=
func
;
Py_INCREF
(
func
);
pto
->
args
=
PyTuple_GetSlice
(
args
,
1
,
PY_SSIZE_T_MAX
);
if
(
pto
->
args
==
NULL
)
{
nargs
=
PyTuple_GetSlice
(
args
,
1
,
PY_SSIZE_T_MAX
);
if
(
nargs
==
NULL
)
{
pto
->
args
=
NULL
;
pto
->
kw
=
NULL
;
Py_DECREF
(
pto
);
return
NULL
;
}
if
(
pargs
==
Py_None
||
PyTuple_GET_SIZE
(
pargs
)
==
0
)
{
pto
->
args
=
nargs
;
Py_INCREF
(
nargs
);
}
else
if
(
PyTuple_GET_SIZE
(
nargs
)
==
0
)
{
pto
->
args
=
pargs
;
Py_INCREF
(
pargs
);
}
else
{
pto
->
args
=
PySequence_Concat
(
pargs
,
nargs
);
if
(
pto
->
args
==
NULL
)
{
pto
->
kw
=
NULL
;
Py_DECREF
(
pto
);
return
NULL
;
}
}
Py_DECREF
(
nargs
);
if
(
kw
!=
NULL
)
{
pto
->
kw
=
PyDict_Copy
(
kw
);
if
(
pkw
==
Py_None
)
{
pto
->
kw
=
PyDict_Copy
(
kw
);
}
else
{
pto
->
kw
=
PyDict_Copy
(
pkw
);
if
(
pto
->
kw
!=
NULL
)
{
if
(
PyDict_Merge
(
pto
->
kw
,
kw
,
1
)
!=
0
)
{
Py_DECREF
(
pto
);
return
NULL
;
}
}
}
if
(
pto
->
kw
==
NULL
)
{
Py_DECREF
(
pto
);
return
NULL
;
}
}
else
{
pto
->
kw
=
Py_None
;
Py_INCREF
(
Py_None
);
}
else
{
pto
->
kw
=
pkw
;
Py_INCREF
(
pkw
);
}
pto
->
weakreflist
=
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