Skip to content

Commit eee0865

Browse files
Do not raise on int
1 parent 399f6bd commit eee0865

9 files changed

+34
-29
lines changed

pylint/checkers/format.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ class FormatChecker(BaseTokenChecker, BaseRawFileChecker):
387387
{
388388
# default big enough to not trigger on pixel perfect web design
389389
# on big screen
390-
"default": "1e8",
390+
"default": "1e6",
391391
"type": "float",
392392
"metavar": "<float>",
393393
"help": (
@@ -679,9 +679,15 @@ def process_tokens(self, tokens: list[tokenize.TokenInfo]) -> None:
679679
if line_num == last_blank_line_num and line_num > 0:
680680
self.add_message("trailing-newlines", line=line_num)
681681

682-
def _check_bad_float_notation( # pylint: disable=too-many-locals
682+
def _check_bad_float_notation( # pylint: disable=too-many-locals,too-many-return-statements
683683
self, line_num: int, start: tuple[int, int], string: str
684684
) -> None:
685+
has_dot = "." in string
686+
has_exponent = "e" in string or "E" in string
687+
if not (has_dot or has_exponent):
688+
# it's an int, need special treatment later on
689+
return None
690+
685691
value = float(string)
686692
engineering = (
687693
self.all_float_notation_allowed
@@ -718,7 +724,6 @@ def raise_bad_float_notation(
718724
# engineering notation when checking if a number is under 1/threshold
719725
return None
720726
has_underscore = "_" in string
721-
has_exponent = "e" in string or "E" in string
722727
should_be_written_simply = (
723728
1 <= value < 10 and self.linter.config.strict_scientific_notation
724729
) or 1 <= value < 1000

tests/functional/b/bad_float/bad_float_engineering_notation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
exponent_not_multiple_of_three = 123e4 # [bad-float-notation]
44
base_not_between_one_and_a_thousand = 12345e6 # [bad-float-notation]
5-
above_threshold_without_exponent = 10000000 # [bad-float-notation]
5+
above_threshold_without_exponent = 10000000.0 # [bad-float-notation]
66
under_a_thousand_with_exponent = 9.9e2 # [bad-float-notation]
77
exponent_multiple_of_three = 1.23e6
88
base_between_one_and_a_thousand = 12.345e9
9-
under_a_thousand = 990
9+
under_a_thousand = 990.0
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
bad-float-notation:3:33:3:38::'123e4' has an exponent '4' that is not a multiple of 3, and it should be written as '1.23e6' instead:HIGH
22
bad-float-notation:4:38:4:45::'12345e6' has a base, '12345.0', that is not between 1 and 1000, and it should be written as '12.344999999999999e9' instead:HIGH
3-
bad-float-notation:5:35:5:43::'10000000' is bigger than 1e6, and it should be written as '10e6' instead:HIGH
3+
bad-float-notation:5:35:5:45::'10000000.0' is bigger than 1e6, and it should be written as '10e6' instead:HIGH
44
bad-float-notation:6:33:6:38::'9.9e2' has underscore or exponent, and it should be written as '990.0' instead:HIGH

tests/functional/b/bad_float/bad_float_notation_default.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,25 @@
77
underscore_notation = 150_400_000
88

99
# Content of pep515 strict tests tested with default configuration
10-
not_grouped_by_three = 1_23_456_7_89 # [bad-float-notation]
10+
not_grouped_by_three = 1_23_456_7_89.0 # [bad-float-notation]
1111
mixing_with_exponent = 1_23_4_5_67_8e9 # [bad-float-notation]
12-
above_threshold_without_grouping = 123456789 # [bad-float-notation]
12+
above_threshold_without_grouping = 123456789.0 # [bad-float-notation]
1313
proper_grouping = 123_456_789
1414
scientific_notation_2 = 1.2345678e16
1515
engineering_notation_2 = 12.345678e15
1616

1717
# Content of bad_float_engineering_notation.py strict tests tested with default configuration
1818
exponent_not_multiple_of_three = 123e4 # [bad-float-notation]
1919
base_not_between_one_and_a_thousand = 12345e6 # [bad-float-notation]
20-
above_threshold_without_exponent = 10000000 # [bad-float-notation]
20+
above_threshold_without_exponent = 10000000.0 # [bad-float-notation]
2121
under_a_thousand_with_exponent = 9.9e2 # [bad-float-notation]
2222
exponent_multiple_of_three = 1.23e6
2323
base_between_one_and_a_thousand = 12.345e9
2424
under_a_thousand = 990
2525

2626
# Content of bad_float_scientific_notation strict tests tested with default configuration
2727
base_not_between_one_and_ten = 10e3
28-
above_threshold_without_exponent_2 = 10000000 # [bad-float-notation]
28+
above_threshold_without_exponent_2 = 10000000.0 # [bad-float-notation]
2929
under_ten_with_exponent = 9.9e0 # [bad-float-notation]
3030
base_between_one_and_ten = 1e4
3131
above_threshold_with_exponent = 1e7
@@ -46,7 +46,7 @@
4646
zero_only = 0e10 # [bad-float-notation]
4747
zero_int = 0
4848
zero_float = 0.0
49-
annoying_zero = 00 # [bad-float-notation]
49+
annoying_zero = 00.0 # [bad-float-notation]
5050
another_annoying_zero = 0. # [bad-float-notation]
5151

5252
one_only = 1e6
@@ -137,6 +137,6 @@ def function_with_underscore(param=10.0_0e3, other_param=20.0_0e3):
137137
#+3: [bad-float-notation]
138138
#+3: [bad-float-notation]
139139
#+3: [bad-float-notation]
140-
time_in_s_since_two_week_ago_at_16 = 1180800 # 2 * 24 * 3600 - (8 * 3600)
141-
time_in_s_since_last_year = 31536000 # 365 * 24 * 3600
142-
time_in_s_since_last_month = 2592000 # 30 * 24 * 3600
140+
time_in_s_since_two_week_ago_at_16 = 1180800.0 # 2 * 24 * 3600 - (8 * 3600)
141+
time_in_s_since_last_year = 31536000.0 # 365 * 24 * 3600
142+
time_in_s_since_last_month = 2592000.0 # 30 * 24 * 3600

tests/functional/b/bad_float/bad_float_notation_default.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
bad-float-notation:4:19:4:25::'1504e5' has a base, '1504.0', that is not between 1 and 1000, and it should be written as '1.504e8' or '150.4e6' or '150_400_000.0' instead:HIGH
2-
bad-float-notation:10:23:10:36::'1_23_456_7_89' has underscores that are not delimiting packs of three digits, and it should be written as '1.23456789e8' or '123.45678899999999e6' or '123_456_789.0' instead:HIGH
2+
bad-float-notation:10:23:10:38::'1_23_456_7_89.0' has underscores that are not delimiting packs of three digits, and it should be written as '1.23456789e8' or '123.45678899999999e6' or '123_456_789.0' instead:HIGH
33
bad-float-notation:11:23:11:38::'1_23_4_5_67_8e9' has exponent and underscore at the same time, and it should be written as '1.2345678e+16' or '1.2345678e16' or '12.345678e15' instead:HIGH
4-
bad-float-notation:12:35:12:44::'123456789' is bigger than 1e6, and it should be written as '1.23456789e8' or '123.45678899999999e6' or '123_456_789.0' instead:HIGH
4+
bad-float-notation:12:35:12:46::'123456789.0' is bigger than 1e6, and it should be written as '1.23456789e8' or '123.45678899999999e6' or '123_456_789.0' instead:HIGH
55
bad-float-notation:18:33:18:38::'123e4' has an exponent '4' that is not a multiple of 3, and it should be written as '1.23e6' or '1_230_000.0' instead:HIGH
66
bad-float-notation:19:38:19:45::'12345e6' has a base, '12345.0', that is not between 1 and 1000, and it should be written as '1.2345e10' or '12.344999999999999e9' or '12_345_000_000.0' instead:HIGH
7-
bad-float-notation:20:35:20:43::'10000000' is bigger than 1e6, and it should be written as '10_000_000.0' or '10e6' or '1e7' instead:HIGH
7+
bad-float-notation:20:35:20:45::'10000000.0' is bigger than 1e6, and it should be written as '10_000_000.0' or '10e6' or '1e7' instead:HIGH
88
bad-float-notation:21:33:21:38::'9.9e2' has underscore or exponent, and it should be written as '9.9e2' or '990.0' instead:HIGH
9-
bad-float-notation:28:37:28:45::'10000000' is bigger than 1e6, and it should be written as '10_000_000.0' or '10e6' or '1e7' instead:HIGH
9+
bad-float-notation:28:37:28:47::'10000000.0' is bigger than 1e6, and it should be written as '10_000_000.0' or '10e6' or '1e7' instead:HIGH
1010
bad-float-notation:29:26:29:31::'9.9e0' has underscore or exponent, and it should be written as '9.9' instead:HIGH
1111
bad-float-notation:35:12:35:18::'45.3e7' has an exponent '7' that is not a multiple of 3, and it should be written as '4.53e8' or '453_000_000.0' or '453e6' instead:HIGH
1212
bad-float-notation:36:20:36:26::'45.3E7' has an exponent '7' that is not a multiple of 3, and it should be written as '4.53e8' or '453_000_000.0' or '453e6' instead:HIGH
@@ -19,7 +19,7 @@ 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:18::'00' is smaller than 1e-6, 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
2323
bad-float-notation:50:24:50:26::'0.' is smaller than 1e-6, and it should be written as '0.0' instead:HIGH
2424
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
2525
bad-float-notation:65:16:65:19::'9e0' has underscore or exponent, and it should be written as '9.0' instead:HIGH
@@ -53,6 +53,6 @@ bad-float-notation:121:21:121:28::'1.5_6e3' has exponent and underscore at the s
5353
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
5454
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
5555
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:44::'1180800' 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:36::'31536000' 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:36::'2592000' is bigger than 1e6, and it should be written as '2.592e6' or '2_592_000.0' or '3600 * 24 * 30' 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
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# pylint: disable=missing-docstring,invalid-name
22

3-
not_grouped_by_three = 1_23_456_7_89 # [bad-float-notation]
3+
not_grouped_by_three = 1_23_456_7_89.0 # [bad-float-notation]
44
mixing_with_exponent = 1_23_4_5_67_8e9 # [bad-float-notation]
5-
above_threshold_without_grouping = 123456789 # [bad-float-notation]
5+
above_threshold_without_grouping = 123456789.0 # [bad-float-notation]
66
scientific_notation = 1.2345678e16 # [bad-float-notation]
77
engineering_notation = 12.345678e15 # [bad-float-notation]
88

9-
proper_grouping = 123_456_789
9+
proper_grouping = 123_456_789.0
1010

1111
int_under_ten = 9
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
bad-float-notation:3:23:3:36::'1_23_456_7_89' has underscores that are not delimiting packs of three digits, and it should be written as '123_456_789.0' instead:HIGH
1+
bad-float-notation:3:23:3:38::'1_23_456_7_89.0' has underscores that are not delimiting packs of three digits, and it should be written as '123_456_789.0' instead:HIGH
22
bad-float-notation:4:23:4:38::'1_23_4_5_67_8e9' has exponent and underscore at the same time, and it should be written as '1.2345678e+16' instead:HIGH
3-
bad-float-notation:5:35:5:44::'123456789' is bigger than 1e6, and it should be written as '123_456_789.0' instead:HIGH
3+
bad-float-notation:5:35:5:46::'123456789.0' is bigger than 1e6, and it should be written as '123_456_789.0' instead:HIGH
44
bad-float-notation:6:22:6:34::'1.2345678e16' has exponent and underscore at the same time, and it should be written as '1.2345678e+16' instead:HIGH
55
bad-float-notation:7:23:7:35::'12.345678e15' has exponent and underscore at the same time, and it should be written as '1.2345678e+16' instead:HIGH

tests/functional/b/bad_float/bad_float_scientific_notation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# pylint: disable=missing-docstring,invalid-name
22

33
base_not_between_one_and_ten = 10e3 # [bad-float-notation]
4-
above_threshold_without_exponent = 10000000 # [bad-float-notation]
4+
above_threshold_without_exponent = 10000000.0 # [bad-float-notation]
55
under_ten_with_exponent = 9.9e0 # [bad-float-notation]
66
base_between_one_and_ten = 1e4
77
above_threshold_with_exponent = 1e7
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
bad-float-notation:3:31:3:35::'10e3' has a base, '10.0', that is not strictly inferior to 10, and it should be written as '1e4' instead:HIGH
2-
bad-float-notation:4:35:4:43::'10000000' is bigger than 1e6, and it should be written as '1e7' instead:HIGH
2+
bad-float-notation:4:35:4:45::'10000000.0' is bigger than 1e6, and it should be written as '1e7' instead:HIGH
33
bad-float-notation:5:26:5:31::'9.9e0' has underscore or exponent, and it should be written as '9.9' instead:HIGH

0 commit comments

Comments
 (0)