Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mypy-nonfloat-decimal

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mypy-nonfloat-decimal

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

  • 0.1.7
  • PyPI
  • Socket score

Maintainers
1

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

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc