[pypy-svn] r56194 - in pypy/dist: lib-python/modified-2.4.1 pypy/lib pypy/lib/app_test
fijal at codespeak.net
fijal at codespeak.net
Mon Jun 30 23:56:48 CEST 2008
Author: fijal
Date: Mon Jun 30 23:56:46 2008
New Revision: 56194
Added:
pypy/dist/lib-python/modified-2.4.1/functools.py
Removed:
pypy/dist/pypy/lib/functools.py
Modified:
pypy/dist/pypy/lib/app_test/test_functools.py
Log:
Do a proper thing. Put functools.py from python svn to lib-python/modified,
so it'll reuse existing _functools.py. thx xoraxax for pointing out.
Pass more tests.
Added: pypy/dist/lib-python/modified-2.4.1/functools.py
==============================================================================
--- (empty file)
+++ pypy/dist/lib-python/modified-2.4.1/functools.py Mon Jun 30 23:56:46 2008
@@ -0,0 +1,52 @@
+"""functools.py - Tools for working with functions and callable objects
+"""
+# Python module wrapper for _functools C module
+# to allow utilities written in Python to be added
+# to the functools module.
+# Written by Nick Coghlan <ncoghlan at gmail.com>
+# Copyright (C) 2006 Python Software Foundation.
+# See C source code for _functools credits/copyright
+
+from _functools import partial
+from __builtin__ import reduce
+
+# update_wrapper() and wraps() are tools to help write
+# wrapper functions that can handle naive introspection
+
+WRAPPER_ASSIGNMENTS = ('__module__', '__name__', '__doc__')
+WRAPPER_UPDATES = ('__dict__',)
+def update_wrapper(wrapper,
+ wrapped,
+ assigned = WRAPPER_ASSIGNMENTS,
+ updated = WRAPPER_UPDATES):
+ """Update a wrapper function to look like the wrapped function
+
+ wrapper is the function to be updated
+ wrapped is the original function
+ assigned is a tuple naming the attributes assigned directly
+ from the wrapped function to the wrapper function (defaults to
+ functools.WRAPPER_ASSIGNMENTS)
+ updated is a tuple naming the attributes of the wrapper that
+ are updated with the corresponding attribute from the wrapped
+ function (defaults to functools.WRAPPER_UPDATES)
+ """
+ for attr in assigned:
+ setattr(wrapper, attr, getattr(wrapped, attr))
+ for attr in updated:
+ getattr(wrapper, attr).update(getattr(wrapped, attr, {}))
+ # Return the wrapper so this can be used as a decorator via partial()
+ return wrapper
+
+def wraps(wrapped,
+ assigned = WRAPPER_ASSIGNMENTS,
+ updated = WRAPPER_UPDATES):
+ """Decorator factory to apply update_wrapper() to a wrapper function
+
+ Returns a decorator that invokes update_wrapper() with the decorated
+ function as the wrapper argument and the arguments to wraps() as the
+ remaining arguments. Default arguments are as for update_wrapper().
+ This is a convenience function to simplify applying partial() to
+ update_wrapper().
+ """
+ return partial(update_wrapper, wrapped=wrapped,
+ assigned=assigned, updated=updated)
Modified: pypy/dist/pypy/lib/app_test/test_functools.py
==============================================================================
--- pypy/dist/pypy/lib/app_test/test_functools.py (original)
+++ pypy/dist/pypy/lib/app_test/test_functools.py Mon Jun 30 23:56:46 2008
@@ -119,7 +119,6 @@
py.test.raises(ZeroDivisionError, self.thetype(f, y=0), 1)
def test_attributes(self):
- py.test.skip("Unsupported")
p = self.thetype(hex)
try:
del p.__dict__
@@ -129,7 +128,6 @@
raise AssertionError, 'partial object allowed __dict__ to be deleted'
def test_weakref(self):
- py.test.skip("unsupported")
f = self.thetype(int, base=16)
p = proxy(f)
assert f.func == p.func
@@ -143,12 +141,12 @@
join = self.thetype(''.join)
assert join(data) == '0123456789'
-#class PartialSubclass(functools.partial):
-# pass
+class PartialSubclass(functools.partial):
+ pass
-#class TestPartialSubclass(TestPartial):
+class TestPartialSubclass(TestPartial):
-# thetype = PartialSubclass
+ thetype = PartialSubclass
class TestPythonPartial(TestPartial):
@@ -214,7 +212,6 @@
assert wrapper.dict_attr == f.dict_attr
def test_builtin_update(self):
- py.test.skip("Unsupported")
# Test for bug #1576241
def wrapper():
pass
More information about the Pypy-commit
mailing list