Generate .pyi stub files from existing modules
Project description
Macrotype
Consider this:
VAL = 42
def get() -> type(VAL):
return VAL
This is perfectly valid python, but type checkers don't accept it. Instead, you are supposed to write out all type references statically, or use very limited global aliases.
macrotype makes this work exactly as you expect, with all static
type checkers. So your types can be as dynamic as the rest of your
python code.
How?
macrotype is a CLI tool intended to be run before static type checking:
macrotype your_module
macrotype imports your modules under normal python,
and then generates corresponding .pyi files with
all types pinned statically so the type checker can understand them.
In our example, macrotype would generate this:
VAL: int
def get() -> int: ...
macrotype is the bridge between static type checkers
and your dynamic code. macrotype will import your modules as
python, and then re-export the runtime types back out into a form
that static type checkers can consume.
What else?
In addition to the CLI tool, there are also helpers for generating
dynamic types. See macrotype.meta_types. These are intended
for you to import to enable dynamic programming patterns which
would be unthinkable without macrotype.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file macrotype-0.2.0.tar.gz.
File metadata
- Download URL: macrotype-0.2.0.tar.gz
- Upload date:
- Size: 29.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b9860c21295bd8d15070ac05858094548fcac7ba5edbeb477860eb3ad916985
|
|
| MD5 |
c5217d7add5de96d00d9064aa38d2d62
|
|
| BLAKE2b-256 |
6214e6dd965e7174e4bd07670c7e778d70bbeb5785ddbe8b90bf063b10f27589
|
File details
Details for the file macrotype-0.2.0-py3-none-any.whl.
File metadata
- Download URL: macrotype-0.2.0-py3-none-any.whl
- Upload date:
- Size: 37.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48d49390a64714a28d7b78b6be994094922cdd237c004f4bd93fa3a2623c7776
|
|
| MD5 |
a576db89062ab6111c34678c0781186f
|
|
| BLAKE2b-256 |
e43a6948ed3036617a6c1be07a7d3498243bb4650319f79573a7d13de1c881f3
|