MartinThoma / flake8-simplify

❄ A flake8 plugin that helps you to simplify code
MIT License
186 stars 19 forks source link

[New Rule] Underscores in Numeric Literals #150

Open zephvr opened 2 years ago

zephvr commented 2 years ago

Explanation

Using underscore on large number make for better comprehension.

This feature was introduced with python 3.6 and PEP515 describe it.

Example

# Bad
amount = 10000000.0
addr = 0xCAFEF00D
flags = 0b0011111101001110
flags = int('0b11110000', 2)

# Good
amount = 10_000_000.0
addr = 0xCAFE_F00D
flags = 0b_0011_1111_0100_1110
flags = int('0b_1111_0000', 2)
Marenz commented 1 year ago

Related: https://github.com/frequenz-floss/flake8-numbers/pull/4/files