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
floatpassed toDecimaland 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)
| File | Size | Uploaded | |
|---|---|---|---|
| mypy_nonfloat_decimal-0.1.8.tar.gz | 3.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| 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
|