Skip to content

Commit

Permalink
functools: Implement partial().
Browse files Browse the repository at this point in the history
  • Loading branch information
pfalcon committed May 19, 2014
1 parent d3761c3 commit 7b02354
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
6 changes: 6 additions & 0 deletions functools/functools.py
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions functools/metadata.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
srctype = micropython-lib
type = module
version = 0.0.1
24 changes: 12 additions & 12 deletions functools/setup.py
Original file line number Diff line number Diff line change
@@ -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'])
8 changes: 8 additions & 0 deletions functools/test_partial.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 7b02354

Please sign in to comment.