Skip to content

Commit 292fc36

Browse files
Special case 0. too
1 parent eee0865 commit 292fc36

File tree

3 files changed

+40
-40
lines changed

3 files changed

+40
-40
lines changed

pylint/checkers/format.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ def raise_bad_float_notation(
718718
confidence=HIGH,
719719
)
720720

721-
if string in {"0", "0.0"}:
721+
if string in {"0", "0.0", "0."}:
722722
# 0 is a special case because it is used very often, and float approximation
723723
# being what they are it needs to be special cased anyway for scientific and
724724
# engineering notation when checking if a number is under 1/threshold

tests/functional/b/bad_float/bad_float_notation_default.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@
4646
zero_only = 0e10 # [bad-float-notation]
4747
zero_int = 0
4848
zero_float = 0.0
49-
annoying_zero = 00.0 # [bad-float-notation]
50-
another_annoying_zero = 0. # [bad-float-notation]
49+
zero_float_v2 = 0.
50+
annoying_zero_int = 00
51+
annoying_zero_float = 00.0 # [bad-float-notation]
5152

5253
one_only = 1e6
5354
correct_1 = 4.53e7

tests/functional/b/bad_float/bad_float_notation_default.txt

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,40 +19,39 @@ bad-float-notation:43:28:43:37::'0.0001e-5' has a base, '0.0001', that is not be
1919
bad-float-notation:44:26:44:34::'0.0001e5' has underscore or exponent, and it should be written as '10.0' or '1e1' instead:HIGH
2020
bad-float-notation:45:20:45:26::'0.5e10' has a base, '0.5', that is not between 1 and 1000, and it should be written as '5_000_000_000.0' or '5e9' instead:HIGH
2121
bad-float-notation:46:12:46:16::'0e10' has a base, '0.0', that is not between 1 and 1000, and it should be written as '0.0' instead:HIGH
22-
bad-float-notation:49:16:49:20::'00.0' is smaller than 1e-6, and it should be written as '0.0' instead:HIGH
23-
bad-float-notation:50:24:50:26::'0.' is smaller than 1e-6, and it should be written as '0.0' instead:HIGH
24-
bad-float-notation:64:25:64:30::'1.5e1' has underscore or exponent, and it should be written as '1.5e1' or '15.0' instead:HIGH
25-
bad-float-notation:65:16:65:19::'9e0' has underscore or exponent, and it should be written as '9.0' instead:HIGH
26-
bad-float-notation:66:15:66:20::'1.0e0' has underscore or exponent, and it should be written as '1.0' instead:HIGH
27-
bad-float-notation:82:23:82:27::'15e4' has an exponent '4' that is not a multiple of 3, and it should be written as '1.5e5' or '150_000.0' or '150e3' instead:HIGH
28-
bad-float-notation:87:28:87:34::'10.0e4' has an exponent '4' that is not a multiple of 3, and it should be written as '100_000.0' or '100e3' or '1e5' instead:HIGH
29-
bad-float-notation:87:48:87:54::'20.0e5' has an exponent '5' that is not a multiple of 3, and it should be written as '2_000_000.0' or '2e6' instead:HIGH
30-
bad-float-notation:91:35:91:41::'10.0e7' has an exponent '7' that is not a multiple of 3, and it should be written as '100_000_000.0' or '100e6' or '1e8' instead:HIGH
31-
bad-float-notation:91:27:91:33::'20.0e4' has an exponent '4' that is not a multiple of 3, and it should be written as '200_000.0' or '200e3' or '2e5' instead:HIGH
32-
bad-float-notation:95:29:95:57::'123_000_000.12345e12_000_000' has exponent and underscore at the same time, and it should be written as 'inf.0' or 'math.inf' instead:HIGH
33-
bad-float-notation:96:33:96:62::'123_000_000.12345E123_000_000' has exponent and underscore at the same time, and it should be written as 'inf.0' or 'math.inf' instead:HIGH
34-
bad-float-notation:101:34:101:42::'.123_456' has underscores that are not delimiting packs of three digits, and it should be written as '0.123456' or '1.23456e-1' or '123.45600000000002e-3' instead:HIGH
35-
bad-float-notation:102:35:102:50::'123_456.123_456' has underscores that are not delimiting packs of three digits, and it should be written as '1.23456123456e5' or '123.45612345600001e3' or '123_456.123456' instead:HIGH
36-
bad-float-notation:103:27:103:38::'1.234_567e6' has exponent and underscore at the same time, and it should be written as '1.234567e6' or '1_234_567.0' instead:HIGH
37-
bad-float-notation:104:26:104:37::'1.234_567E6' has exponent and underscore at the same time, and it should be written as '1.234567e6' or '1_234_567.0' instead:HIGH
38-
bad-float-notation:105:31:105:38::'1.2e1_0' has exponent and underscore at the same time, and it should be written as '1.2e10' or '12_000_000_000.0' or '12e9' instead:HIGH
39-
bad-float-notation:106:27:106:39::'1_234.567_89' has underscores that are not delimiting packs of three digits, and it should be written as '1.23456789e3' or '1_234.56789' instead:HIGH
40-
bad-float-notation:107:23:107:32::'45.3_45e6' has exponent and underscore at the same time, and it should be written as '4.5345e7' or '45.345000000000006e6' or '45_345_000.0' instead:HIGH
41-
bad-float-notation:108:25:108:37::'0.000_12e-26' has exponent and underscore at the same time, and it should be written as '1.2e-30' instead:HIGH
42-
bad-float-notation:109:37:109:42::'1_2e8' has exponent and underscore at the same time, and it should be written as '1.2e9' or '1_200_000_000.0' instead:HIGH
43-
bad-float-notation:110:37:110:43::'12_3e3' has exponent and underscore at the same time, and it should be written as '1.23e5' or '123_000.0' or '123e3' instead:HIGH
44-
bad-float-notation:111:25:111:40::'1_234.567_89e10' has exponent and underscore at the same time, and it should be written as '1.23456789e13' or '12.3456789e12' or '12_345_678_900_000.0' instead:HIGH
45-
bad-float-notation:112:29:112:36::'1.2e1_0' has exponent and underscore at the same time, and it should be written as '1.2e10' or '12_000_000_000.0' or '12e9' instead:HIGH
46-
bad-float-notation:113:34:113:45::'1_2.3_4e5_6' has exponent and underscore at the same time, and it should be written as '1.234e+57' or '1.234e57' instead:HIGH
47-
bad-float-notation:114:24:114:39::'1_234.567_89E10' has exponent and underscore at the same time, and it should be written as '1.23456789e13' or '12.3456789e12' or '12_345_678_900_000.0' instead:HIGH
48-
bad-float-notation:115:20:115:25::'1_0e6' has exponent and underscore at the same time, and it should be written as '10_000_000.0' or '10e6' or '1e7' instead:HIGH
49-
bad-float-notation:116:21:116:35::'1_000_000.0e-3' has exponent and underscore at the same time, and it should be written as '1_000.0' or '1e3' instead:HIGH
50-
bad-float-notation:117:21:117:32::'0.000_001e3' has exponent and underscore at the same time, and it should be written as '0.001' or '1e-3' instead:HIGH
51-
bad-float-notation:118:21:118:28::'1_0.0e2' has exponent and underscore at the same time, and it should be written as '1_000.0' or '1e3' instead:HIGH
52-
bad-float-notation:121:21:121:28::'1.5_6e3' has exponent and underscore at the same time, and it should be written as '1.56e3' or '1_560.0' instead:HIGH
53-
bad-float-notation:122:27:122:33::'15_6e2' has exponent and underscore at the same time, and it should be written as '1.56e4' or '15.600000000000001e3' or '15_600.0' instead:HIGH
54-
bad-float-notation:125:35:125:43::'10.0_0e3' has exponent and underscore at the same time, and it should be written as '10_000.0' or '10e3' or '1e4' instead:HIGH
55-
bad-float-notation:125:57:125:65::'20.0_0e3' has exponent and underscore at the same time, and it should be written as '20_000.0' or '20e3' or '2e4' instead:HIGH
56-
bad-float-notation:140:37:140:46::'1180800.0' is bigger than 1e6, and it should be written as '1.1808e6' or '1_180_800.0' or '3600 * 328' instead:HIGH
57-
bad-float-notation:141:28:141:38::'31536000.0' is bigger than 1e6, and it should be written as '3.1536e7' or '31.536e6' or '31_536_000.0' or '3600 * 24 * 365' instead:HIGH
58-
bad-float-notation:142:29:142:38::'2592000.0' is bigger than 1e6, and it should be written as '2.592e6' or '2_592_000.0' or '3600 * 24 * 30' instead:HIGH
22+
bad-float-notation:51:22:51:26::'00.0' is smaller than 1e-6, and it should be written as '0.0' instead:HIGH
23+
bad-float-notation:65:25:65:30::'1.5e1' has underscore or exponent, and it should be written as '1.5e1' or '15.0' instead:HIGH
24+
bad-float-notation:66:16:66:19::'9e0' has underscore or exponent, and it should be written as '9.0' instead:HIGH
25+
bad-float-notation:67:15:67:20::'1.0e0' has underscore or exponent, and it should be written as '1.0' instead:HIGH
26+
bad-float-notation:83:23:83:27::'15e4' has an exponent '4' that is not a multiple of 3, and it should be written as '1.5e5' or '150_000.0' or '150e3' instead:HIGH
27+
bad-float-notation:88:28:88:34::'10.0e4' has an exponent '4' that is not a multiple of 3, and it should be written as '100_000.0' or '100e3' or '1e5' instead:HIGH
28+
bad-float-notation:88:48:88:54::'20.0e5' has an exponent '5' that is not a multiple of 3, and it should be written as '2_000_000.0' or '2e6' instead:HIGH
29+
bad-float-notation:92:35:92:41::'10.0e7' has an exponent '7' that is not a multiple of 3, and it should be written as '100_000_000.0' or '100e6' or '1e8' instead:HIGH
30+
bad-float-notation:92:27:92:33::'20.0e4' has an exponent '4' that is not a multiple of 3, and it should be written as '200_000.0' or '200e3' or '2e5' instead:HIGH
31+
bad-float-notation:96:29:96:57::'123_000_000.12345e12_000_000' has exponent and underscore at the same time, and it should be written as 'inf.0' or 'math.inf' instead:HIGH
32+
bad-float-notation:97:33:97:62::'123_000_000.12345E123_000_000' has exponent and underscore at the same time, and it should be written as 'inf.0' or 'math.inf' instead:HIGH
33+
bad-float-notation:102:34:102:42::'.123_456' has underscores that are not delimiting packs of three digits, and it should be written as '0.123456' or '1.23456e-1' or '123.45600000000002e-3' instead:HIGH
34+
bad-float-notation:103:35:103:50::'123_456.123_456' has underscores that are not delimiting packs of three digits, and it should be written as '1.23456123456e5' or '123.45612345600001e3' or '123_456.123456' instead:HIGH
35+
bad-float-notation:104:27:104:38::'1.234_567e6' has exponent and underscore at the same time, and it should be written as '1.234567e6' or '1_234_567.0' instead:HIGH
36+
bad-float-notation:105:26:105:37::'1.234_567E6' has exponent and underscore at the same time, and it should be written as '1.234567e6' or '1_234_567.0' instead:HIGH
37+
bad-float-notation:106:31:106:38::'1.2e1_0' has exponent and underscore at the same time, and it should be written as '1.2e10' or '12_000_000_000.0' or '12e9' instead:HIGH
38+
bad-float-notation:107:27:107:39::'1_234.567_89' has underscores that are not delimiting packs of three digits, and it should be written as '1.23456789e3' or '1_234.56789' instead:HIGH
39+
bad-float-notation:108:23:108:32::'45.3_45e6' has exponent and underscore at the same time, and it should be written as '4.5345e7' or '45.345000000000006e6' or '45_345_000.0' instead:HIGH
40+
bad-float-notation:109:25:109:37::'0.000_12e-26' has exponent and underscore at the same time, and it should be written as '1.2e-30' instead:HIGH
41+
bad-float-notation:110:37:110:42::'1_2e8' has exponent and underscore at the same time, and it should be written as '1.2e9' or '1_200_000_000.0' instead:HIGH
42+
bad-float-notation:111:37:111:43::'12_3e3' has exponent and underscore at the same time, and it should be written as '1.23e5' or '123_000.0' or '123e3' instead:HIGH
43+
bad-float-notation:112:25:112:40::'1_234.567_89e10' has exponent and underscore at the same time, and it should be written as '1.23456789e13' or '12.3456789e12' or '12_345_678_900_000.0' instead:HIGH
44+
bad-float-notation:113:29:113:36::'1.2e1_0' has exponent and underscore at the same time, and it should be written as '1.2e10' or '12_000_000_000.0' or '12e9' instead:HIGH
45+
bad-float-notation:114:34:114:45::'1_2.3_4e5_6' has exponent and underscore at the same time, and it should be written as '1.234e+57' or '1.234e57' instead:HIGH
46+
bad-float-notation:115:24:115:39::'1_234.567_89E10' has exponent and underscore at the same time, and it should be written as '1.23456789e13' or '12.3456789e12' or '12_345_678_900_000.0' instead:HIGH
47+
bad-float-notation:116:20:116:25::'1_0e6' has exponent and underscore at the same time, and it should be written as '10_000_000.0' or '10e6' or '1e7' instead:HIGH
48+
bad-float-notation:117:21:117:35::'1_000_000.0e-3' has exponent and underscore at the same time, and it should be written as '1_000.0' or '1e3' instead:HIGH
49+
bad-float-notation:118:21:118:32::'0.000_001e3' has exponent and underscore at the same time, and it should be written as '0.001' or '1e-3' instead:HIGH
50+
bad-float-notation:119:21:119:28::'1_0.0e2' has exponent and underscore at the same time, and it should be written as '1_000.0' or '1e3' instead:HIGH
51+
bad-float-notation:122:21:122:28::'1.5_6e3' has exponent and underscore at the same time, and it should be written as '1.56e3' or '1_560.0' instead:HIGH
52+
bad-float-notation:123:27:123:33::'15_6e2' has exponent and underscore at the same time, and it should be written as '1.56e4' or '15.600000000000001e3' or '15_600.0' instead:HIGH
53+
bad-float-notation:126:35:126:43::'10.0_0e3' has exponent and underscore at the same time, and it should be written as '10_000.0' or '10e3' or '1e4' instead:HIGH
54+
bad-float-notation:126:57:126:65::'20.0_0e3' has exponent and underscore at the same time, and it should be written as '20_000.0' or '20e3' or '2e4' instead:HIGH
55+
bad-float-notation:141:37:141:46::'1180800.0' is bigger than 1e6, and it should be written as '1.1808e6' or '1_180_800.0' or '3600 * 328' instead:HIGH
56+
bad-float-notation:142:28:142:38::'31536000.0' is bigger than 1e6, and it should be written as '3.1536e7' or '31.536e6' or '31_536_000.0' or '3600 * 24 * 365' instead:HIGH
57+
bad-float-notation:143:29:143:38::'2592000.0' is bigger than 1e6, and it should be written as '2.592e6' or '2_592_000.0' or '3600 * 24 * 30' instead:HIGH

0 commit comments

Comments
 (0)