Skip to content

Commit 1db9508

Browse files
Some design and add doc to give an idea of the design before actual implementation
1 parent 354dd44 commit 1db9508

File tree

16 files changed

+371
-174
lines changed

16 files changed

+371
-174
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mindless_anarchy = 1504e5 # [bad-float-notation]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
exponent_not_multiple_of_three = 123e4 # [bad-float-notation]
2+
base_not_between_one_and_a_thousand = 12345e6 # [bad-float-notation]
3+
above_threshold_without_exponent = 10000000 # [bad-float-notation]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
not_grouped_by_three = 1_23_456_7_89 # [bad-float-notation]
2+
mixing_with_exponent = 1_23_4_5_67_8e9 # [bad-float-notation]
3+
above_threshold_without_grouping = 123456789 # [bad-float-notation]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
base_not_between_one_and_10 = 10e3 # [bad-float-notation]
2+
above_threshold_without_exponent = 10000000 # [bad-float-notation]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
exponent_multiple_of_three = 1.23e6
2+
base_between_one_and_a_thousand = 12.345e9 # [bad-float-notation]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
scientific_notation = 1.504e8
2+
engineering_notation = 150.4e6
3+
underscore_notation = 150_400_000
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
proper_grouping = 123_456_789
2+
scientific_notation = 1.2345678e16
3+
engineering_notation = 12.345678e15
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
base_between_one_and_10 = 1e4
2+
above_threshold_with_exponent = 1e7

doc/user_guide/checkers/features.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,10 @@ Format checker Messages
557557
Used when there is different newline than expected.
558558
:superfluous-parens (C0325): *Unnecessary parens after %r keyword*
559559
Used when a single item in parentheses follows an if, for, or other keyword.
560+
:bad-float-notation (C0329): *float literal should be written as '%s' instead*
561+
Emitted when a number is written in a non-standard notation. The three
562+
allowed notation above the threshold are the scientific notation, the
563+
engineering notation, and the underscore grouping notation defined in PEP515.
560564

561565

562566
Imports checker

doc/user_guide/configuration/all-options.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,13 @@ Standard Checkers
879879
**Default:** ``""``
880880

881881

882+
--float-notation-threshold
883+
""""""""""""""""""""""""""
884+
*Threshold for float literals to be expected to be written using the scientific, engineering or underscore notation. If the absolute value of a float literal is greater than this value (or smaller than the inverse of this value for scientific and engineering notation), it will be checked.*
885+
886+
**Default:** ``1e6``
887+
888+
882889
--ignore-long-lines
883890
"""""""""""""""""""
884891
*Regexp for a line that is allowed to be longer than the limit.*
@@ -928,6 +935,27 @@ Standard Checkers
928935
**Default:** ``False``
929936

930937

938+
--strict-engineering-notation
939+
"""""""""""""""""""""""""""""
940+
*Only allow engineering notation for float literals with absolute value bigger than 'float-notation-threshold' or smallerthan the inverse of 'float-notation-threshold'.*
941+
942+
**Default:** ``False``
943+
944+
945+
--strict-scientific-notation
946+
""""""""""""""""""""""""""""
947+
*Only allow scientific notation for float literals with absolute value bigger than 'float-notation-threshold' or smallerthan the inverse of 'float-notation-threshold'.*
948+
949+
**Default:** ``False``
950+
951+
952+
--strict-underscore-notation
953+
""""""""""""""""""""""""""""
954+
*Only allow underscore notation for float literals bigger than 'float-notation-threshold'.*
955+
956+
**Default:** ``False``
957+
958+
931959

932960
.. raw:: html
933961

@@ -942,6 +970,8 @@ Standard Checkers
942970
# Possible choices: ['', 'LF', 'CRLF']
943971
expected-line-ending-format = ""
944972
973+
float-notation-threshold = 1000000.0
974+
945975
ignore-long-lines = "^\\s*(# )?<?https?://\\S+>?$"
946976
947977
indent-after-paren = 4
@@ -956,6 +986,12 @@ Standard Checkers
956986
957987
single-line-if-stmt = false
958988
989+
strict-engineering-notation = false
990+
991+
strict-scientific-notation = false
992+
993+
strict-underscore-notation = false
994+
959995
960996
961997
.. raw:: html

0 commit comments

Comments
 (0)