Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

macrotype-0.2.0.tar.gz (29.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

macrotype-0.2.0-py3-none-any.whl (37.9 kB view details)

Uploaded Python 3

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

Hashes for macrotype-0.2.0.tar.gz
Algorithm Hash digest
SHA256 9b9860c21295bd8d15070ac05858094548fcac7ba5edbeb477860eb3ad916985
MD5 c5217d7add5de96d00d9064aa38d2d62
BLAKE2b-256 6214e6dd965e7174e4bd07670c7e778d70bbeb5785ddbe8b90bf063b10f27589

See more details on using hashes here.

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

Hashes for macrotype-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 48d49390a64714a28d7b78b6be994094922cdd237c004f4bd93fa3a2623c7776
MD5 a576db89062ab6111c34678c0781186f
BLAKE2b-256 e43a6948ed3036617a6c1be07a7d3498243bb4650319f79573a7d13de1c881f3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page