Issue #12428: Add a pure Python implementation of functools.partial().
Patch by Brian Thorne.
diff --git a/Lib/functools.py b/Lib/functools.py
index 226a46e..60d2cf1 100644
--- a/Lib/functools.py
+++ b/Lib/functools.py
@@ -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
@@ -137,6 +140,29 @@
 
 
 ################################################################################
+### 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
 ################################################################################