# Handwritten Partial
| See | About |
| --------------------------- | --------------------------- |
| [[Anti-Patterns of Python]] | [[NIH - Not Invented Here]] |
May happens when someone wants to create a pre-configured callable to a function. By creating and returning a closure and calling the function with arguments based on outside scope or hardcoded values, the
```python
# Don't
def decorator(func):
def wrapper(*args, **kwargs):
return func("foobar", *args, **kwargs)
return wrapper
# Or
def decorator(func):
return lambda *args, **kwargs: func("foobar", *args, **kwargs
# Do
def decorator(func):
return functools.partial(func, "foobar")
```
---
Bibliography:
- [functools.partial - docs.python.org](https://docs.python.org/3/library/functools.html#functools.partial)