"""
This replaces any explicit float by a Decimal.
It can be used either as a custom codec or import hook.
"""
from ideas import custom_encoding, import_hook
import token_utils
[docs]def source_init():
"""Adds required import"""
return "from decimal import Decimal\n"
def register():
custom_encoding.register_encoding(
encoding_name="decimal_math",
transform_source=transform_source,
hook_name=__name__,
)
[docs]def add_hook(**_kwargs):
"""Creates and automatically adds the import hook in sys.meta_path"""
hook = import_hook.create_hook(
hook_name=__name__,
source_init=source_init,
transform_source=transform_source,
)
return hook