Skip to main content

tightwrap

PyPI Build Coverage Supported Python Versions Ruff

tightwrap (pronounced typed wrap) is a drop-in replacement for functools.wraps that works with static typing. tightwrap is very small, so if you don't want to add a dependency to it just vendor this file.

functools.wraps is very commonly used to adapt runtime function signatures when wrapping functions, but it doesn't work well with static typing tools. tightwrap.wraps has the same interface and you should use it instead:

from tightwrap import wraps

def function(a: int) -> int:
    return a + 1

@wraps(function)
def wrapping(*args, **kwargs) -> int:
    return function(*args, **kwargs)

reveal_type(wrapping)  # Revealed type is "def (a: builtins.int) -> builtins.int"

wrapping("a string")  # error: Argument 1 to "wrapping" has incompatible type "str"; expected "int"

tightwrap applies functools.wraps under the hood so runtime inspection continues to work.

If your wrapper has a different return type than the function you're wrapping, tightwrap.wraps will use the wrapper return type and make the runtime signature return type match.

For comparison, when using functools.wraps the current version of Mypy reports:

from functools import wraps

def function(a: int) -> int:
    return a + 1

@wraps(function)
def wrapping(*args, **kwargs) -> int:
    return function(*args, **kwargs)

reveal_type(wrapping)  # Revealed type is "def (*args: Any, **kwargs: Any) -> builtins.int"

wrapping("a string")  # No type error, blows up at runtime.

Changelog

26.1.0 (2026-03-04)

  • Add support for wrapping methods with correct typing. (#9)
  • Add support for Python 3.14. (#8)
  • Add support for Python 3.13. (#4)
  • Drop support for Python 3.8 and 3.9. (#8)

24.3.0 (2024-05-24)

  • Fix wrapping unannotated functions. (#2 #3)

24.2.0 (2024-05-04)

  • Add support for Python 3.8 and 3.9. (#1)

24.1.0 (2024-01-09)

  • Initial version.

Release files for tightwrap 26.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tightwrap 26.1.0
File Size Uploaded
tightwrap-26.1.0.tar.gz 139.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tightwrap 26.1.0
File Interpreter ABI Platform
tightwrap-26.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 146.9 kB

Release files / tightwrap-26.1.0.tar.gz

Download URL tightwrap-26.1.0.tar.gz
Size 139.1 kB
Tags Source
SHA-256 checksum
How to use checksums
da963813dae54bd4754f4c50017923c4d88403efe4aa89b5df85577d51cc2a21
BLAKE2b-256 checksum
How to use checksums
70d7a657bf4f55da1a6e48ceb13e991dd4074a3dbd03777a0b228c3a611d43c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 4, 2026.

Transparency log

Release files / tightwrap-26.1.0-py3-none-any.whl

Download URL tightwrap-26.1.0-py3-none-any.whl
Size 7.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a76a4659f9f27d94259a86ee87a5a85a36b6b3a531fe5e43425658b789cbbb33
BLAKE2b-256 checksum
How to use checksums
7c57cb916e28bbb7a27d53a22c332a9077ecbed163a132835acd5d76b937a797
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 4, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

26.1.0 This release

2 release files

24.3.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page