Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
b5b37141
Commit
b5b37141
authored
Nov 13, 2012
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #12428: Add a pure Python implementation of functools.partial().
Patch by Brian Thorne.
parent
65a35dca
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
167 additions
and
73 deletions
+167
-73
Lib/functools.py
Lib/functools.py
+27
-1
Lib/test/test_functools.py
Lib/test/test_functools.py
+136
-72
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/functools.py
View file @
b5b37141
...
...
@@ -11,7 +11,10 @@
__all__
=
[
'update_wrapper'
,
'wraps'
,
'WRAPPER_ASSIGNMENTS'
,
'WRAPPER_UPDATES'
,
'total_ordering'
,
'cmp_to_key'
,
'lru_cache'
,
'reduce'
,
'partial'
]
from
_functools
import
partial
,
reduce
try
:
from
_functools
import
reduce
except
ImportError
:
pass
from
collections
import
namedtuple
try
:
from
_thread
import
allocate_lock
as
Lock
...
...
@@ -136,6 +139,29 @@ except ImportError:
pass
################################################################################
### partial() argument application
################################################################################
def
partial
(
func
,
*
args
,
**
keywords
):
"""new function with partial application of the given arguments
and keywords.
"""
def
newfunc
(
*
fargs
,
**
fkeywords
):
newkeywords
=
keywords
.
copy
()
newkeywords
.
update
(
fkeywords
)
return
func
(
*
(
args
+
fargs
),
**
newkeywords
)
newfunc
.
func
=
func
newfunc
.
args
=
args
newfunc
.
keywords
=
keywords
return
newfunc
try
:
from
_functools
import
partial
except
ImportError
:
pass
################################################################################
### LRU Cache function decorator
################################################################################
...
...
Lib/test/test_functools.py
View file @
b5b37141
This diff is collapsed.
Click to expand it.
Misc/ACKS
View file @
b5b37141
...
...
@@ -1166,6 +1166,7 @@ Tobias Thelen
Nicolas M. Thiéry
James Thomas
Robin Thomas
Brian Thorne
Stephen Thorne
Jeremy Thurgood
Eric Tiedemann
...
...
Misc/NEWS
View file @
b5b37141
...
...
@@ -124,6 +124,9 @@ Core and Builtins
Library
-------
- Issue #12428: Add a pure Python implementation of functools.partial().
Patch by Brian Thorne.
- Issue #16140: The subprocess module no longer double closes its child
subprocess.PIPE parent file descriptors on child error prior to exec().
...
...
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