Diastatic Malt
Diastatic Malt (pypi-slug: `diastatic-malt`) is a Python library (current version 2.15.3) designed for source-to-source transformations and operator overloading, including the ability to overload built-in Python keywords. It allows for transforming regular Python code into a new form suitable for specific purposes, such as program capture. The library's core functionalities are adapted from TensorFlow's AutoGraph module, aiming to provide similar capabilities without a direct TensorFlow dependency. Releases are infrequent and tied to internal needs, with minor versions released as changes are integrated.
Common errors
-
ModuleNotFoundError: No module named 'gast'
cause Upgrading to diastatic-malt v2.15.3 or later removed the `gast` dependency.fixReplace any direct or indirect reliance on `gast` with Python's standard `ast` library. If `gast` is still required by other parts of your project, ensure it is explicitly listed in your `requirements.txt`. -
AttributeError: module 'diastatic_malt' has no attribute 'some_expected_function'
cause The public API for `diastatic-malt` is not extensively documented with typical examples. Many functionalities are likely internal or mirror specific AutoGraph patterns, making expected attribute names non-obvious without deeper understanding of its source or specific use cases.fixRefer to the GitHub repository for the latest source code to identify available classes and functions, or consult projects that leverage `diastatic-malt` for practical usage patterns. The library's main purpose is source transformation, so direct utility functions might be less common than decorator-based or API-driven transformations.
Warnings
- breaking The `gast` dependency has been removed and replaced with the standard library `ast` module.
- gotcha Diastatic Malt (the Python library) is frequently confused with 'diastatic malt powder', a culinary ingredient. This can lead to misleading search results or incorrect assumptions about the library's purpose.
Install
-
pip install diastatic-malt
Imports
- diastatic_malt
import diastatic_malt
Quickstart
import diastatic_malt
# Diastatic Malt is a tool for source-to-source transformations and operator overloading.
# Its primary use case is within contexts requiring Python code transformation,
# similar to TensorFlow's AutoGraph.
# As such, a direct, simple 'quickstart' involves understanding its application
# for modifying Python's AST or operator behavior, rather than a standalone function call.
# Actual usage would depend on the specific transformation or overloading task.
# For example, to enable specific operator overloading for a function:
# def my_function(x, y):
# return x + y
# transformed_function = diastatic_malt.transform(my_function)
# (Note: 'transform' is a hypothetical example as specific API calls are not publicly documented.)
print("Diastatic Malt is installed and available for code transformation tasks.")