diff --git a/functools/functools.py b/functools/functools.py index e69de29b..5e165eed 100644 --- a/functools/functools.py +++ b/functools/functools.py @@ -0,0 +1,6 @@ +def partial(func, *args, **kwargs): + def _partial(*more_args, **more_kwargs): + kw = kwargs.copy() + kw.update(more_kwargs) + func(*(args + more_args), **kw) + return _partial diff --git a/functools/metadata.txt b/functools/metadata.txt new file mode 100644 index 00000000..d252b56c --- /dev/null +++ b/functools/metadata.txt @@ -0,0 +1,3 @@ +srctype = micropython-lib +type = module +version = 0.0.1 diff --git a/functools/setup.py b/functools/setup.py index 48177325..c5503aa8 100644 --- a/functools/setup.py +++ b/functools/setup.py @@ -1,18 +1,18 @@ import sys -# Remove current dir from sys.path, otherwise distutils will peek up our -# module instead of system one. +# Remove current dir from sys.path, otherwise setuptools will peek up our +# module instead of system. sys.path.pop(0) -sys.path.insert(0, '..') from setuptools import setup -import metadata -NAME = 'functools' -setup(name='micropython-' + NAME, - version='0.0.0', - description=metadata.desc_dummy(NAME), - url=metadata.url, - author=metadata.author_upy_devels, - author_email=metadata.author_upy_devels_email, +setup(name='micropython-functools', + version='0.0.1', + description='functools module for MicroPython', + long_description="This is a module reimplemented specifically for MicroPython standard library,\nwith efficient and lean design in mind. Note that this module is likely work\nin progress and likely supports just a subset of CPython's corresponding\nmodule. Please help with the development if you are interested in this\nmodule.", + url='https://github.com/micropython/micropython/issues/405', + author='MicroPython Developers', + author_email='micro-python@googlegroups.com', + maintainer='MicroPython Developers', + maintainer_email='micro-python@googlegroups.com', license='MIT', - py_modules=[NAME]) + py_modules=['functools']) diff --git a/functools/test_partial.py b/functools/test_partial.py new file mode 100644 index 00000000..41305818 --- /dev/null +++ b/functools/test_partial.py @@ -0,0 +1,8 @@ +from functools import partial + +def foo(x, y, prompt="result:"): + print(prompt, x + y) + + +f = partial(foo, 10, prompt="arg+10:") +f(20)