Skip to main content

Mypy non-float Decimal plugin

Restricts passing float numbers to Decimal

Why?

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.020000000000000017763568394002504646778106689453125")
>>> Decimal("1.02")
Decimal("1.02")

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

Usage

  • install plugin
pip install mypy-nonfloat-decimal
  • add it into list of mypy plugins in your mypy config (mypy.ini)
[mypy]
plugins=mypy_nonfloat_decimal
  • upon running mypy will detect float passed to Decimal and report it as an error (example.py):
from decimal import Decimal
Decimal(1.02)
$ mypy --config-file ./mypy.ini ./example.py

example.py:2: error: Invalid type passed to Decimal (expected "Union[int, str, Decimal]"), got float instead

Metadata

Release files for mypy-nonfloat-decimal 0.1.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mypy-nonfloat-decimal 0.1.8
File Size Uploaded
mypy_nonfloat_decimal-0.1.8.tar.gz 3.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mypy-nonfloat-decimal 0.1.8
File Interpreter ABI Platform
mypy_nonfloat_decimal-0.1.8-py3-none-any.whl Python 3 none any Details

Total release size: 7.1 kB

Release files / mypy_nonfloat_decimal-0.1.8.tar.gz

Download URL mypy_nonfloat_decimal-0.1.8.tar.gz
Size 3.0 kB
Tags Source
SHA-256 checksum
How to use checksums
077b3b53815ff128ba83a41370b7f6c917aa9b3d9b548a3ffce96996e442d0e2
BLAKE2b-256 checksum
How to use checksums
5fb90303fbdf4cdd3eb4aee5bd01942e8cb9b6f92bb25b4a1e651b73a9245e42
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.1 CPython/3.12.2 Darwin/24.3.0

Release files / mypy_nonfloat_decimal-0.1.8-py3-none-any.whl

Download URL mypy_nonfloat_decimal-0.1.8-py3-none-any.whl
Size 4.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b4ac8a97cc4463522709ee02bd3cf74d4f61ff851be19b1dc1d513a2fb8f2041
BLAKE2b-256 checksum
How to use checksums
204225de227cfa70b44d019dac1c564b5f94b71e4ddd3b47af7abe0e989107ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.1 CPython/3.12.2 Darwin/24.3.0

Release history Release notifications | RSS feed

This release

0.1.8 This release

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page