# Buggy code
def make_closure(f, handle_arg, handle_output):
    """Create a closure that encodes parameters to utf-8 and call original function."""
    return lambda *args, **kwargs: handle_output(
        f(
            *[handle_arg(arg) for arg in args],
            **{k: handle_arg(arg) for k, arg in kwargs.items()},
        )
    )


# Traceback (TypeError)
python SickBeard.py --help
Traceback (most recent call last):
File "SickBeard.py", line 4, in <module>
from medusa.__main__ import main
File "/opt/share/medusa/Medusa/medusa/__main__.py", line 67, in <module>
from . import (
File "/opt/share/medusa/Medusa/medusa/providers/__init__.py", line 10, in <module>
from medusa.providers.nzb import (
File "/opt/share/medusa/Medusa/medusa/providers/nzb/anizb.py", line 14, in <module>
from medusa.providers.nzb.nzb_provider import NZBProvider
File "/opt/share/medusa/Medusa/medusa/providers/nzb/nzb_provider.py", line 8, in <module>
from medusa.providers.generic_provider import GenericProvider
File "/opt/share/medusa/Medusa/medusa/providers/generic_provider.py", line 18, in <module>
from medusa import (
File "/opt/share/medusa/Medusa/medusa/config.py", line 30, in <module>
from medusa.version_checker import CheckVersion
File "/opt/share/medusa/Medusa/medusa/version_checker.py", line 31, in <module>
from medusa.github_client import get_github_repo
File "/opt/share/medusa/Medusa/medusa/github_client.py", line 6, in <module>
import github
File "/opt/share/medusa/Medusa/ext/github/__init__.py", line 37, in <module>
from MainClass import Github, GithubIntegration
File "/opt/share/medusa/Medusa/ext/github/MainClass.py", line 34, in <module>
import jwt
File "/opt/share/medusa/Medusa/ext/jwt/__init__.py", line 19, in <module>
from .api_jwt import (
File "/opt/share/medusa/Medusa/ext/jwt/api_jwt.py", line 8, in <module>
from .api_jws import PyJWS
File "/opt/share/medusa/Medusa/ext/jwt/api_jws.py", line 7, in <module>
from .algorithms import (
File "/opt/share/medusa/Medusa/ext/jwt/algorithms.py", line 8, in <module>
from .utils import (
File "/opt/share/medusa/Medusa/ext/jwt/utils.py", line 8, in <module>
from cryptography.hazmat.primitives.asymmetric.utils import (
File "/opt/lib/python2.7/site-packages/cryptography/hazmat/primitives/asymmetric/utils.py", line 9, in <module>
File "/opt/lib/python2.7/site-packages/asn1crypto/algos.py", line 23, in <module>
from ._int import fill_width
File "/opt/lib/python2.7/site-packages/asn1crypto/_int.py", line 56, in <module>
from ._perf._big_num_ctypes import libcrypto
File "/opt/lib/python2.7/site-packages/asn1crypto/_perf/_big_num_ctypes.py", line 35, in <module>
libcrypto_path = find_library(b'crypto' if sys.version_info < (3,) else 'crypto')
File "/opt/lib/python2.7/ctypes/util.py", line 274, in find_library
File "/opt/lib/python2.7/ctypes/util.py", line 107, in _findLib_gcc
File "/opt/lib/python2.7/tempfile.py", line 431, in close
File "/opt/share/medusa/Medusa/medusa/init/filesystem.py", line 85, in <lambda>
return lambda *args, **kwargs: handle_output(f(*[handle_arg(arg) for arg in args], **{k: handle_arg(arg) for k, arg in kwargs.items()}))
TypeError: remove() takes exactly 1 argument (2 given)

# Fixed code
def make_closure(f, handle_arg=None, handle_output=None):
    """Apply an input handler and output handler to a function.

    Used to ensure UTF-8 encoding at input and output.
    """
    return patch_output(patch_input(f, handle_arg), handle_output)