Registry / type-stubs / strip-hints

strip-hints

JSON →
library0.1.13pypypi✓ verified 27d ago

strip-hints is a Python library and command-line program designed to remove type hints from Python code files. It aims to leave runnable code while making minimal changes to preserve line and column numbers, aiding in debugging of the stripped output. It supports stripping hints from strings, individual files, or via an import hook for automatic processing. The current version is 0.1.13, and it is actively maintained on a feature-driven release cadence.

pip install strip-hints
INSTALL
IMPORT
SIG · STRIP-HINTS
S
strip-hints
type-stubspythonv0.1.13
Install
1.7s avg
Import
—
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.1.13 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.9MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 1.7s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

strip_string_hints
✓ from strip_hints import strip_string_hints
✗ from strip_hints import strip_string_hints

Demonstrates how to use `strip_string_hints` for in-memory string processing and `strip_file_hints` for processing Python files. The `strip_file_hints` function can output to stdout or a specified file.

import os from strip_hints import strip_string_hints, strip_file_hints # Example 1: Stripping hints from a string code_with_hints = """ def greet(name: str) -> str: return f"Hello, {name}" """ stripped_code = strip_string_hints(code_with_hints) print("--- Stripped String ---") print(stripped_code) # Example 2: Stripping hints from a file (creating a dummy file first) file_content = """ # my_module.py def add(a: int, b: int) -> int: return a + b def subtract(x: float, y: float) -> float: return x - y """ with open("my_module_with_hints.py", "w") as f: f.write(file_content) output_filename = "my_module_stripped.py" # Strip hints and write to a new file strip_file_hints("my_module_with_hints.py", outfile=output_filename) print("\n--- Stripped File Content (my_module_stripped.py) ---") with open(output_filename, "r") as f: print(f.read()) # Clean up dummy files os.remove("my_module_with_hints.py") os.remove(output_filename)
strip-hints --version
Debug
Known issues
gotchaUsing options like `--strip-nl` (also strip non-logical newline tokens) or `--to-empty` (map removed code to empty strings) can alter the original line and column numbers. This can make debugging the stripped code harder by breaking correspondence with the original source.
fix
Avoid `--strip-nl` and `--to-empty` if exact line/column number correspondence is critical for debugging. The default behavior attempts to preserve these.
affects: All versions
gotchaThe `--no-equal-move` command-line option prevents the program from adjusting annotated assignments that include newlines in their type hints. If such a situation occurs with this option enabled, it will raise an exception rather than attempting a syntactically correct transformation.
fix
Unless you specifically need to disallow the transformation, avoid using `--no-equal-move`. If an exception occurs, remove this flag or refactor your type hints to avoid newlines in annotated assignments.
affects: All versions
gotchaThe library allows disabling stripping for specific code sections using `# strip-hints: off` and re-enabling with `# strip-hints: on`. Accidentally leaving these directives in or misplacing them can lead to unexpected behavior where hints are either retained or stripped in unintended areas.
fix
Carefully manage `# strip-hints: off` and `# strip-hints: on` directives, ensuring they are correctly placed and removed when no longer needed.
affects: All versions
deprecatedThe primary use case of `strip-hints` was originally for Python 2 compatibility (developing with Python 3 hints, running on Python 2). Python 2 is no longer maintained, and the library is no longer tested against it. The `install_import_hook` mechanism also uses the `imp` module, which is deprecated for Python 3. Users should target Python 3.
fix
Assume Python 3 as the target environment. If using `install_import_hook`, be aware of the underlying deprecated `imp` module.
affects: All versions (historical context, affects current expectations)
gotchaStripping type hints removes runtime metadata. If other tools or frameworks in your ecosystem rely on runtime inspection of `__annotations__` or `typing.get_type_hints` (e.g., for dependency injection, API schema generation, or validation), using `strip-hints` will remove this crucial information, potentially causing runtime errors or unexpected behavior in those tools.
fix
Understand that `strip-hints` fundamentally alters the runtime availability of type annotations. Only use it when downstream consumers of the code do not require runtime type information, or if that information is recreated/managed by another mechanism.
affects: All versions
Upgrade
Version history
0.1.13latest on PyPI · released Feb 21, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
35 hits · last 30 days
node
32
OpenAI (training)
1
Resources