Name | type-stripper JSON |
Version |
0.1.5
JSON |
| download |
home_page | None |
Summary | A CLI tool that removes type annotations from Python source files. |
upload_time | 2025-01-09 17:20:30 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.9 |
license | None |
keywords |
transpiler
typing
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# type-stripper
Python package that strips type annotations from a source file,
printing the modified file to stdout.
## Installation
Install from [PyPI](https://pypi.org/project/type-stripper/):
```sh
pip install type-stripper
```
## Usage
Runs as a CLI tool. Give it a file path:
```sh
type-stripper /path/to/file.py
```
...and the results of the changes will be sent to stdout.
This output can be piped back to a file:
```sh
type-stripper /path/to/file.py > newfile.py
```
Use `type-stripper --help` for details.
## What it does
- Parameter annotations in function definitions are removed:
```diff
- def func(a: int, b: str = "30", c: int = 42, *args: str, **kwargs: dict[str, int]):
+ def func(a, b = "30", c = 42, *args, **kwargs):
```
- Return-type annotations are removed:
```diff
- def func() -> str:
+ def func():
```
- Annotations in variable assignments are removed:
```diff
- x: int = 10
+ x = 10
```
- Bare annotation statements are removed entirely:
```diff
- x: int
```
Formatting, comments, and all other syntax remains unchanged.
### What it does not do
Some of the resulting code's format may be stylistically incorrect:
```diff
# Given:
- def foo(a: int = 4):
# Produces:
+ def foo(a = 4):
# What it probably should produce (note the spacing):
+ def foo(a=4):
```
You may wish to run results through a formatter first.
## How?
This package uses [`libcst`](https://github.com/Instagram/LibCST)
to parse the Concrete Syntax Tree of an input module,
then modifies (or removes) nodes in that tree to strip type annotations away.
A similar task could be completed in Python's [`ast`](https://docs.python.org/3/library/ast.html) module,
however the AST does not preserve code structure or syntax the way CST does.
## Why?
For fun ~~and profit~~. 🙂
There are some potential use cases, however:
- **Backwards compatibility**:
Code developed on modern Python versions with type hinting
may not work on older versions of Python.
While I would strongly recommend migrating to a more recent version of Python,
this tool can get code working faster.
- **Other Python variants**:
Some Python dialects
(such as [Starlark](https://github.com/bazelbuild/starlark))
may use the same Python syntax, but may not (now or ever) support type annotations.
This tool can be used to transpile code meant for more "standard" Python flavors
to work in these environments.
- **Smaller file size**:
Need to shave precious bytes off a Docker image build
and your type hints are not relevant to the runtime
(i.e., not using FastAPI where type annotations are critical)?
Strip those type hints off to reduce file sizes to their bare minimum.
- **Reduced complexity when teaching**:
Modern Python code with type annotations may be difficult
for the newest beginners to comprehend.
While teaching how data types interact is important,
some learners may benefit from the reduced noise in their code samples.
Absolutely none of these statements are qualified or tested:
I just sort of made them up.
Take it as you will!
## Contributing
See [CONTRIBUTING.md](CONTRIBUTING.md)
Raw data
{
"_id": null,
"home_page": null,
"name": "type-stripper",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "transpiler, typing",
"author": null,
"author_email": "Galen Rice <griceturrble@protonmail.com>",
"download_url": "https://files.pythonhosted.org/packages/fe/05/37b0fe8f39fb1d38c9e9040af349e5922a6419c7556d29ab3a3a0211f8d2/type_stripper-0.1.5.tar.gz",
"platform": null,
"description": "# type-stripper\n\nPython package that strips type annotations from a source file,\nprinting the modified file to stdout.\n\n## Installation\n\nInstall from [PyPI](https://pypi.org/project/type-stripper/):\n\n```sh\npip install type-stripper\n```\n\n## Usage\n\nRuns as a CLI tool. Give it a file path:\n\n```sh\ntype-stripper /path/to/file.py\n```\n\n...and the results of the changes will be sent to stdout.\n\nThis output can be piped back to a file:\n\n```sh\ntype-stripper /path/to/file.py > newfile.py\n```\n\nUse `type-stripper --help` for details.\n\n## What it does\n\n- Parameter annotations in function definitions are removed:\n\n ```diff\n - def func(a: int, b: str = \"30\", c: int = 42, *args: str, **kwargs: dict[str, int]):\n + def func(a, b = \"30\", c = 42, *args, **kwargs):\n ```\n\n- Return-type annotations are removed:\n\n ```diff\n - def func() -> str:\n + def func():\n ```\n\n- Annotations in variable assignments are removed:\n\n ```diff\n - x: int = 10\n + x = 10\n ```\n\n- Bare annotation statements are removed entirely:\n\n ```diff\n - x: int\n ```\n\nFormatting, comments, and all other syntax remains unchanged.\n\n### What it does not do\n\nSome of the resulting code's format may be stylistically incorrect:\n\n```diff\n# Given:\n- def foo(a: int = 4):\n\n# Produces:\n+ def foo(a = 4):\n\n# What it probably should produce (note the spacing):\n+ def foo(a=4):\n```\n\nYou may wish to run results through a formatter first.\n\n## How?\n\nThis package uses [`libcst`](https://github.com/Instagram/LibCST)\nto parse the Concrete Syntax Tree of an input module,\nthen modifies (or removes) nodes in that tree to strip type annotations away.\n\nA similar task could be completed in Python's [`ast`](https://docs.python.org/3/library/ast.html) module,\nhowever the AST does not preserve code structure or syntax the way CST does.\n\n## Why?\n\nFor fun ~~and profit~~. \ud83d\ude42\n\nThere are some potential use cases, however:\n\n- **Backwards compatibility**:\n Code developed on modern Python versions with type hinting\n may not work on older versions of Python.\n While I would strongly recommend migrating to a more recent version of Python,\n this tool can get code working faster.\n- **Other Python variants**:\n Some Python dialects\n (such as [Starlark](https://github.com/bazelbuild/starlark))\n may use the same Python syntax, but may not (now or ever) support type annotations.\n This tool can be used to transpile code meant for more \"standard\" Python flavors\n to work in these environments.\n- **Smaller file size**:\n Need to shave precious bytes off a Docker image build\n and your type hints are not relevant to the runtime\n (i.e., not using FastAPI where type annotations are critical)?\n Strip those type hints off to reduce file sizes to their bare minimum.\n- **Reduced complexity when teaching**:\n Modern Python code with type annotations may be difficult\n for the newest beginners to comprehend.\n While teaching how data types interact is important,\n some learners may benefit from the reduced noise in their code samples.\n\nAbsolutely none of these statements are qualified or tested:\nI just sort of made them up.\nTake it as you will!\n\n## Contributing\n\nSee [CONTRIBUTING.md](CONTRIBUTING.md)\n",
"bugtrack_url": null,
"license": null,
"summary": "A CLI tool that removes type annotations from Python source files.",
"version": "0.1.5",
"project_urls": {
"homepage": "https://github.com/griceturrble/python-type-stripper"
},
"split_keywords": [
"transpiler",
" typing"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "496fd9c6858a476c8d75719099ece9ccd816b60838cad72bd24beed25cb70bff",
"md5": "9a540879c9f53b9e91fd971cf1a86d94",
"sha256": "16e42a4fbb6a1b3984c9cf11cfe7b79ff06d1cca438c2497de1185a0946cc3c3"
},
"downloads": -1,
"filename": "type_stripper-0.1.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9a540879c9f53b9e91fd971cf1a86d94",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 8082,
"upload_time": "2025-01-09T17:20:28",
"upload_time_iso_8601": "2025-01-09T17:20:28.542479Z",
"url": "https://files.pythonhosted.org/packages/49/6f/d9c6858a476c8d75719099ece9ccd816b60838cad72bd24beed25cb70bff/type_stripper-0.1.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "fe0537b0fe8f39fb1d38c9e9040af349e5922a6419c7556d29ab3a3a0211f8d2",
"md5": "15416c264030910d34a2241397c15ab0",
"sha256": "9c018b11e02fcecb99e7f3bbaeaeec1d5c7788f048d65e470117c384792b12a3"
},
"downloads": -1,
"filename": "type_stripper-0.1.5.tar.gz",
"has_sig": false,
"md5_digest": "15416c264030910d34a2241397c15ab0",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 31997,
"upload_time": "2025-01-09T17:20:30",
"upload_time_iso_8601": "2025-01-09T17:20:30.086436Z",
"url": "https://files.pythonhosted.org/packages/fe/05/37b0fe8f39fb1d38c9e9040af349e5922a6419c7556d29ab3a3a0211f8d2/type_stripper-0.1.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-09 17:20:30",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "griceturrble",
"github_project": "python-type-stripper",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "type-stripper"
}