makefun
Dynamically create Python functions with a proper, correct signature for decorators and generators.
Repository Health
Technical Analysis
makefun is a small, focused Python library for dynamically creating functions that expose a proper, accurate signature. Where Python’s built-in metaprogramming often produces wrappers with a generic *args/**kwargs signature, makefun lets you generate functions whose signature matches exactly what callers, IDEs, and introspection tools expect.
It is widely used as the engine behind advanced decorators, signature-preserving wrappers, and programmatically generated APIs. With helpers like create_function, wraps, and partial, makefun gives library authors precise control over generated callables while keeping runtime overhead low.
What You Get
- create_function to build a callable from any signature specification and an implementation handler
- A signature-preserving wraps decorator that improves on functools.wraps
- partial that produces correctly-signed partially-applied functions
- with_signature decorator for changing a function’s exposed signature
- Support for positional-only, keyword-only, and variadic parameters across Python versions
Common Use Cases
- Writing decorators that preserve the wrapped function’s exact signature
- Generating API functions dynamically from schemas or configuration
- Creating signature-accurate partial functions for cleaner public APIs
- Building test fixtures and mocks that mimic real function signatures
Under The Hood
Architecture - makefun’s core lives in src/makefun and revolves around create_function, which parses a signature specification into an inspect.Signature, compiles a thin dispatcher function that exposes that signature, and routes all calls to a user-provided implementation handler that receives the bound arguments. Convenience decorators (wraps, with_signature, partial) are built on top of this primitive, and a compatibility layer smooths over differences in the inspect module across supported Python versions.
Tech Stack - Pure Python packaged with setuptools/pyproject, tested via nox with pytest, and checked with flake8 and coverage. It is essentially dependency-free at runtime, targeting a wide range of Python versions.
Code Quality - The project carries strong CI: JUnit test reports, coverage badges, and flake8 linting are all published. Tests are thorough and the codebase is compact, though development activity has slowed as the library is feature-complete for its narrow purpose.
API Design - The public API is small and discoverable: create_function for full control, plus decorators that read like their functools counterparts. Documentation on the project site includes worked examples, and the signature-first design makes intent explicit.
Used by 2 apps in this directory
knowhere
AI Development · Developer Tools
Transform messy, unstructured documents into persistent, navigable memory that AI agents can actually use.
Polar
Ecommerce · Developer Tools · Invoicing Finance
Open source payments infrastructure that turns software into a business — subscriptions, usage-based billing, digital products, and merchant-of-record compliance in one platform.