Skip to main content

Type-Driven Development for Python: Shapes of Types

Project description

pytyped-macros

pytyped-macros is a core piece of pytyped Python packages that allows analysis of a given Python type and its breakdown into primitive type combinators. In this way, pytyped-macros facilitate pytyped's main goal of type-driven development in Python. pytyped-macros is designed to be an extensible base class upon which other type derivations are implemented. In order to see examples of how pytyped-macros can be used, look at pytyped-json, and pytyped-metrics.

Installation

You can install pytyped-macros from PyPI:

pip install pytyped-macros

pytyped-macros is checked on Python 3.6+.

Why pytyped-macros?

To our knowledge, pytyped-macros is the only Python package that supports type-based automation for all typing constructs including even recursive types that, up to this day, are not even fully supported by Python itself. Additionally, pytyped-macros is designed to be extensible. That is, you can create a sub-class of pytyped-macros's Extractor class to automate type derivation for your own task. To see examples of how this is done in practice, look at pytyped-json which uses pytyped-macros in order to automatically derive JSON decoders/encoders for a given Python type.

Currently, pytyped-macros supports the following type driven derivations:

  • Derivations for basic types such as int, bool, date, datetime, str, and Decimal.
  • Derivations for simple usual combinators such as List[T] and Dict[A, B].
  • Derivations for named product types such as NamedTuples or dataclasses.
  • Derivations for anonymous product types such as Tuple[T1, T2, ...].
  • Derivations for anonymous union types such as Optional[T], Union[T1, T2, ...], etc.
  • Derivations for named union types such as class hierarchies (i.e., when a class A has several subclasses A1, ..., An).
  • Derivations for generic types and type variables.
  • Derivations for custom functional types such as Set[T], Secret[T], etc where a custom function is defined for generic types such as Set or Secret and that functional is applied to all instantiations of those generic type.
  • Derivations for recursive types such as binary trees, etc.

Defining New Type Automations

You can follow the examples of pytyped-json (for JSON decoders and JSON encoders), or pytyped-metrics for metric exporters to define new type-based automations. You just need to extend pytyped.macros.extractor.Extractor and implement the abstrtact methods there.

Issues

Please report any issues to the GitHub repository for this package.

Contributors

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

pytyped-macros-1.0.0.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

pytyped_macros-1.0.0-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file pytyped-macros-1.0.0.tar.gz.

File metadata

  • Download URL: pytyped-macros-1.0.0.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.10

File hashes

Hashes for pytyped-macros-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d9cda72da3d87efc3d1584778494562e7bc0ee22d350f2c0dbf5e1dcdf8127cb
MD5 20eaddf4846146d53cb75c2ae39c913c
BLAKE2b-256 3c1c409874c71045c694cad39b7d89fc95b37f1029dd1297a2a8e6c52de2a498

See more details on using hashes here.

File details

Details for the file pytyped_macros-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytyped_macros-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 92bcc75b426c314a864ef125a314b1b5ce95b9c68362e7f4176b160d6e0ccf67
MD5 f01d98af08a97481157f71613536476e
BLAKE2b-256 218829abddc3064ba44acadf9f4df996464c1ffe1ea07fe1696368f39fd6e3a3

See more details on using hashes here.

Supported by

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