Skip to main content

Mypy plugin to prevent passing float type to Decimal to avoid imprecisions.

Project description

Mypy non-float Decimal plugin

Restricts passing float numbers to Decimal


The implementation of floating point numbers can cause imprecisions in results. To avoid this problem you can use Decimal type, however you still need to avoid passing float as its parameter:

>>> Decimal(1.02)
>>> Decimal("1.02")

This plugin is meant to spot occurrences where float is passed to Decimal in your code.


  • install plugin
pip install mypy-nonfloat-decimal
  • add it into list of mypy plugins in your mypy config (mypy.ini)
  • upon running mypy will detect float passed to Decimal and report it as an error (
from decimal import Decimal
$ mypy --config-file ./mypy.ini ./ error: Invalid type passed to Decimal (expected "Union[int, str, Decimal]"), got float instead

Project details

Download files

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

Files for mypy-nonfloat-decimal, version 0.1.4
Filename, size File type Python version Upload date Hashes
Filename, size mypy_nonfloat_decimal-0.1.4-py3-none-any.whl (3.8 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size mypy-nonfloat-decimal-0.1.4.tar.gz (3.4 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page