mirror of https://github.com/astral-sh/ruff
[`flake8-bugbear`] Add more immutable functions for `B008` (#3764)
This commit is contained in:
parent
756e9956a2
commit
bfecf684ce
|
|
@ -1,5 +1,6 @@
|
|||
import collections
|
||||
import datetime as dt
|
||||
from decimal import Decimal
|
||||
import logging
|
||||
import operator
|
||||
import random
|
||||
|
|
@ -165,6 +166,22 @@ def float_str_not_inf_or_nan_is_wrong(value=float("3.14")):
|
|||
pass
|
||||
|
||||
|
||||
# Allow decimals
|
||||
def decimal_okay(value=Decimal("0.1")):
|
||||
pass
|
||||
|
||||
# Allow dates
|
||||
def date_okay(value=dt.date(2023, 3, 27)):
|
||||
pass
|
||||
|
||||
# Allow datetimes
|
||||
def datetime_okay(value=dt.datetime(2023, 3, 27, 13, 51, 59)):
|
||||
pass
|
||||
|
||||
# Allow timedeltas
|
||||
def timedelta_okay(value=dt.timedelta(hours=1)):
|
||||
pass
|
||||
|
||||
# B006 and B008
|
||||
# We should handle arbitrary nesting of these B008.
|
||||
def nested_combo(a=[float(3), dt.datetime.now()]):
|
||||
|
|
|
|||
|
|
@ -32,6 +32,10 @@ impl Violation for FunctionCallInDefaultArgument {
|
|||
const IMMUTABLE_FUNCS: &[&[&str]] = &[
|
||||
&["", "tuple"],
|
||||
&["", "frozenset"],
|
||||
&["datetime", "date"],
|
||||
&["datetime", "datetime"],
|
||||
&["datetime", "timedelta"],
|
||||
&["decimal", "Decimal"],
|
||||
&["operator", "attrgetter"],
|
||||
&["operator", "itemgetter"],
|
||||
&["operator", "methodcaller"],
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@ expression: diagnostics
|
|||
suggestion: ~
|
||||
fixable: false
|
||||
location:
|
||||
row: 60
|
||||
row: 61
|
||||
column: 24
|
||||
end_location:
|
||||
row: 60
|
||||
row: 61
|
||||
column: 33
|
||||
fix:
|
||||
edits: []
|
||||
|
|
@ -22,10 +22,10 @@ expression: diagnostics
|
|||
suggestion: ~
|
||||
fixable: false
|
||||
location:
|
||||
row: 64
|
||||
row: 65
|
||||
column: 29
|
||||
end_location:
|
||||
row: 64
|
||||
row: 65
|
||||
column: 31
|
||||
fix:
|
||||
edits: []
|
||||
|
|
@ -36,10 +36,10 @@ expression: diagnostics
|
|||
suggestion: ~
|
||||
fixable: false
|
||||
location:
|
||||
row: 68
|
||||
row: 69
|
||||
column: 19
|
||||
end_location:
|
||||
row: 68
|
||||
row: 69
|
||||
column: 24
|
||||
fix:
|
||||
edits: []
|
||||
|
|
@ -50,10 +50,10 @@ expression: diagnostics
|
|||
suggestion: ~
|
||||
fixable: false
|
||||
location:
|
||||
row: 72
|
||||
row: 73
|
||||
column: 19
|
||||
end_location:
|
||||
row: 72
|
||||
row: 73
|
||||
column: 44
|
||||
fix:
|
||||
edits: []
|
||||
|
|
@ -64,10 +64,10 @@ expression: diagnostics
|
|||
suggestion: ~
|
||||
fixable: false
|
||||
location:
|
||||
row: 76
|
||||
row: 77
|
||||
column: 31
|
||||
end_location:
|
||||
row: 76
|
||||
row: 77
|
||||
column: 56
|
||||
fix:
|
||||
edits: []
|
||||
|
|
@ -78,10 +78,10 @@ expression: diagnostics
|
|||
suggestion: ~
|
||||
fixable: false
|
||||
location:
|
||||
row: 80
|
||||
row: 81
|
||||
column: 25
|
||||
end_location:
|
||||
row: 80
|
||||
row: 81
|
||||
column: 44
|
||||
fix:
|
||||
edits: []
|
||||
|
|
@ -92,10 +92,10 @@ expression: diagnostics
|
|||
suggestion: ~
|
||||
fixable: false
|
||||
location:
|
||||
row: 85
|
||||
row: 86
|
||||
column: 45
|
||||
end_location:
|
||||
row: 85
|
||||
row: 86
|
||||
column: 69
|
||||
fix:
|
||||
edits: []
|
||||
|
|
@ -106,10 +106,10 @@ expression: diagnostics
|
|||
suggestion: ~
|
||||
fixable: false
|
||||
location:
|
||||
row: 89
|
||||
row: 90
|
||||
column: 45
|
||||
end_location:
|
||||
row: 89
|
||||
row: 90
|
||||
column: 72
|
||||
fix:
|
||||
edits: []
|
||||
|
|
@ -120,10 +120,10 @@ expression: diagnostics
|
|||
suggestion: ~
|
||||
fixable: false
|
||||
location:
|
||||
row: 93
|
||||
row: 94
|
||||
column: 44
|
||||
end_location:
|
||||
row: 93
|
||||
row: 94
|
||||
column: 68
|
||||
fix:
|
||||
edits: []
|
||||
|
|
@ -134,10 +134,10 @@ expression: diagnostics
|
|||
suggestion: ~
|
||||
fixable: false
|
||||
location:
|
||||
row: 97
|
||||
row: 98
|
||||
column: 32
|
||||
end_location:
|
||||
row: 97
|
||||
row: 98
|
||||
column: 34
|
||||
fix:
|
||||
edits: []
|
||||
|
|
@ -148,10 +148,10 @@ expression: diagnostics
|
|||
suggestion: ~
|
||||
fixable: false
|
||||
location:
|
||||
row: 170
|
||||
row: 187
|
||||
column: 19
|
||||
end_location:
|
||||
row: 170
|
||||
row: 187
|
||||
column: 48
|
||||
fix:
|
||||
edits: []
|
||||
|
|
@ -162,10 +162,10 @@ expression: diagnostics
|
|||
suggestion: ~
|
||||
fixable: false
|
||||
location:
|
||||
row: 203
|
||||
row: 220
|
||||
column: 26
|
||||
end_location:
|
||||
row: 203
|
||||
row: 220
|
||||
column: 28
|
||||
fix:
|
||||
edits: []
|
||||
|
|
@ -176,10 +176,10 @@ expression: diagnostics
|
|||
suggestion: ~
|
||||
fixable: false
|
||||
location:
|
||||
row: 204
|
||||
row: 221
|
||||
column: 34
|
||||
end_location:
|
||||
row: 204
|
||||
row: 221
|
||||
column: 36
|
||||
fix:
|
||||
edits: []
|
||||
|
|
@ -190,10 +190,10 @@ expression: diagnostics
|
|||
suggestion: ~
|
||||
fixable: false
|
||||
location:
|
||||
row: 205
|
||||
row: 222
|
||||
column: 61
|
||||
end_location:
|
||||
row: 205
|
||||
row: 222
|
||||
column: 66
|
||||
fix:
|
||||
edits: []
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@ expression: diagnostics
|
|||
suggestion: ~
|
||||
fixable: false
|
||||
location:
|
||||
row: 85
|
||||
row: 86
|
||||
column: 60
|
||||
end_location:
|
||||
row: 85
|
||||
row: 86
|
||||
column: 68
|
||||
fix:
|
||||
edits: []
|
||||
|
|
@ -22,10 +22,10 @@ expression: diagnostics
|
|||
suggestion: ~
|
||||
fixable: false
|
||||
location:
|
||||
row: 89
|
||||
row: 90
|
||||
column: 63
|
||||
end_location:
|
||||
row: 89
|
||||
row: 90
|
||||
column: 71
|
||||
fix:
|
||||
edits: []
|
||||
|
|
@ -36,10 +36,10 @@ expression: diagnostics
|
|||
suggestion: ~
|
||||
fixable: false
|
||||
location:
|
||||
row: 93
|
||||
row: 94
|
||||
column: 59
|
||||
end_location:
|
||||
row: 93
|
||||
row: 94
|
||||
column: 67
|
||||
fix:
|
||||
edits: []
|
||||
|
|
@ -50,10 +50,10 @@ expression: diagnostics
|
|||
suggestion: ~
|
||||
fixable: false
|
||||
location:
|
||||
row: 109
|
||||
row: 110
|
||||
column: 38
|
||||
end_location:
|
||||
row: 109
|
||||
row: 110
|
||||
column: 49
|
||||
fix:
|
||||
edits: []
|
||||
|
|
@ -64,38 +64,24 @@ expression: diagnostics
|
|||
suggestion: ~
|
||||
fixable: false
|
||||
location:
|
||||
row: 113
|
||||
row: 114
|
||||
column: 11
|
||||
end_location:
|
||||
row: 113
|
||||
row: 114
|
||||
column: 28
|
||||
fix:
|
||||
edits: []
|
||||
parent: ~
|
||||
- kind:
|
||||
name: FunctionCallInDefaultArgument
|
||||
body: "Do not perform function call `dt.timedelta` in argument defaults"
|
||||
suggestion: ~
|
||||
fixable: false
|
||||
location:
|
||||
row: 113
|
||||
column: 31
|
||||
end_location:
|
||||
row: 113
|
||||
column: 51
|
||||
fix:
|
||||
edits: []
|
||||
parent: ~
|
||||
- kind:
|
||||
name: FunctionCallInDefaultArgument
|
||||
body: Do not perform function call in argument defaults
|
||||
suggestion: ~
|
||||
fixable: false
|
||||
location:
|
||||
row: 117
|
||||
row: 118
|
||||
column: 29
|
||||
end_location:
|
||||
row: 117
|
||||
row: 118
|
||||
column: 44
|
||||
fix:
|
||||
edits: []
|
||||
|
|
@ -106,10 +92,10 @@ expression: diagnostics
|
|||
suggestion: ~
|
||||
fixable: false
|
||||
location:
|
||||
row: 155
|
||||
row: 156
|
||||
column: 33
|
||||
end_location:
|
||||
row: 155
|
||||
row: 156
|
||||
column: 47
|
||||
fix:
|
||||
edits: []
|
||||
|
|
@ -120,10 +106,10 @@ expression: diagnostics
|
|||
suggestion: ~
|
||||
fixable: false
|
||||
location:
|
||||
row: 160
|
||||
row: 161
|
||||
column: 29
|
||||
end_location:
|
||||
row: 160
|
||||
row: 161
|
||||
column: 37
|
||||
fix:
|
||||
edits: []
|
||||
|
|
@ -134,10 +120,10 @@ expression: diagnostics
|
|||
suggestion: ~
|
||||
fixable: false
|
||||
location:
|
||||
row: 164
|
||||
row: 165
|
||||
column: 44
|
||||
end_location:
|
||||
row: 164
|
||||
row: 165
|
||||
column: 57
|
||||
fix:
|
||||
edits: []
|
||||
|
|
@ -148,10 +134,10 @@ expression: diagnostics
|
|||
suggestion: ~
|
||||
fixable: false
|
||||
location:
|
||||
row: 170
|
||||
row: 187
|
||||
column: 20
|
||||
end_location:
|
||||
row: 170
|
||||
row: 187
|
||||
column: 28
|
||||
fix:
|
||||
edits: []
|
||||
|
|
@ -162,10 +148,10 @@ expression: diagnostics
|
|||
suggestion: ~
|
||||
fixable: false
|
||||
location:
|
||||
row: 170
|
||||
row: 187
|
||||
column: 30
|
||||
end_location:
|
||||
row: 170
|
||||
row: 187
|
||||
column: 47
|
||||
fix:
|
||||
edits: []
|
||||
|
|
@ -176,10 +162,10 @@ expression: diagnostics
|
|||
suggestion: ~
|
||||
fixable: false
|
||||
location:
|
||||
row: 176
|
||||
row: 193
|
||||
column: 21
|
||||
end_location:
|
||||
row: 176
|
||||
row: 193
|
||||
column: 62
|
||||
fix:
|
||||
edits: []
|
||||
|
|
@ -190,10 +176,10 @@ expression: diagnostics
|
|||
suggestion: ~
|
||||
fixable: false
|
||||
location:
|
||||
row: 181
|
||||
row: 198
|
||||
column: 18
|
||||
end_location:
|
||||
row: 181
|
||||
row: 198
|
||||
column: 59
|
||||
fix:
|
||||
edits: []
|
||||
|
|
@ -204,10 +190,10 @@ expression: diagnostics
|
|||
suggestion: ~
|
||||
fixable: false
|
||||
location:
|
||||
row: 181
|
||||
row: 198
|
||||
column: 36
|
||||
end_location:
|
||||
row: 181
|
||||
row: 198
|
||||
column: 53
|
||||
fix:
|
||||
edits: []
|
||||
|
|
|
|||
Loading…
Reference in New Issue