From 7d962bf80c63ab161b907d9df3f614e6518f64bf Mon Sep 17 00:00:00 2001 From: Andy Freeland Date: Wed, 29 Mar 2023 08:42:43 -0700 Subject: [PATCH] [`flake8-bugbear`] Allow `pathlib.Path()` in `B008` (#3794) --- .../test/fixtures/flake8_bugbear/B006_B008.py | 5 ++ .../rules/function_call_argument_default.rs | 1 + ...ke8_bugbear__tests__B006_B006_B008.py.snap | 56 +++++++++---------- ...ke8_bugbear__tests__B008_B006_B008.py.snap | 56 +++++++++---------- 4 files changed, 62 insertions(+), 56 deletions(-) diff --git a/crates/ruff/resources/test/fixtures/flake8_bugbear/B006_B008.py b/crates/ruff/resources/test/fixtures/flake8_bugbear/B006_B008.py index 5ebe35e8c9..0fa3d6dc5b 100644 --- a/crates/ruff/resources/test/fixtures/flake8_bugbear/B006_B008.py +++ b/crates/ruff/resources/test/fixtures/flake8_bugbear/B006_B008.py @@ -3,6 +3,7 @@ import datetime as dt from decimal import Decimal import logging import operator +from pathlib import Path import random import re import time @@ -182,6 +183,10 @@ def datetime_okay(value=dt.datetime(2023, 3, 27, 13, 51, 59)): def timedelta_okay(value=dt.timedelta(hours=1)): pass +# Allow paths +def path_okay(value=Path(".")): + pass + # B006 and B008 # We should handle arbitrary nesting of these B008. def nested_combo(a=[float(3), dt.datetime.now()]): diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/function_call_argument_default.rs b/crates/ruff/src/rules/flake8_bugbear/rules/function_call_argument_default.rs index 1046c8cebf..7de79ee843 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/function_call_argument_default.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/function_call_argument_default.rs @@ -39,6 +39,7 @@ const IMMUTABLE_FUNCS: &[&[&str]] = &[ &["operator", "attrgetter"], &["operator", "itemgetter"], &["operator", "methodcaller"], + &["pathlib", "Path"], &["types", "MappingProxyType"], &["re", "compile"], ]; diff --git a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B006_B006_B008.py.snap b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B006_B006_B008.py.snap index 4b3924364f..2a91294c59 100644 --- a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B006_B006_B008.py.snap +++ b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B006_B006_B008.py.snap @@ -8,10 +8,10 @@ expression: diagnostics suggestion: ~ fixable: false location: - row: 61 + row: 62 column: 24 end_location: - row: 61 + row: 62 column: 33 fix: edits: [] @@ -22,10 +22,10 @@ expression: diagnostics suggestion: ~ fixable: false location: - row: 65 + row: 66 column: 29 end_location: - row: 65 + row: 66 column: 31 fix: edits: [] @@ -36,10 +36,10 @@ expression: diagnostics suggestion: ~ fixable: false location: - row: 69 + row: 70 column: 19 end_location: - row: 69 + row: 70 column: 24 fix: edits: [] @@ -50,10 +50,10 @@ expression: diagnostics suggestion: ~ fixable: false location: - row: 73 + row: 74 column: 19 end_location: - row: 73 + row: 74 column: 44 fix: edits: [] @@ -64,10 +64,10 @@ expression: diagnostics suggestion: ~ fixable: false location: - row: 77 + row: 78 column: 31 end_location: - row: 77 + row: 78 column: 56 fix: edits: [] @@ -78,10 +78,10 @@ expression: diagnostics suggestion: ~ fixable: false location: - row: 81 + row: 82 column: 25 end_location: - row: 81 + row: 82 column: 44 fix: edits: [] @@ -92,10 +92,10 @@ expression: diagnostics suggestion: ~ fixable: false location: - row: 86 + row: 87 column: 45 end_location: - row: 86 + row: 87 column: 69 fix: edits: [] @@ -106,10 +106,10 @@ expression: diagnostics suggestion: ~ fixable: false location: - row: 90 + row: 91 column: 45 end_location: - row: 90 + row: 91 column: 72 fix: edits: [] @@ -120,10 +120,10 @@ expression: diagnostics suggestion: ~ fixable: false location: - row: 94 + row: 95 column: 44 end_location: - row: 94 + row: 95 column: 68 fix: edits: [] @@ -134,10 +134,10 @@ expression: diagnostics suggestion: ~ fixable: false location: - row: 98 + row: 99 column: 32 end_location: - row: 98 + row: 99 column: 34 fix: edits: [] @@ -148,10 +148,10 @@ expression: diagnostics suggestion: ~ fixable: false location: - row: 187 + row: 192 column: 19 end_location: - row: 187 + row: 192 column: 48 fix: edits: [] @@ -162,10 +162,10 @@ expression: diagnostics suggestion: ~ fixable: false location: - row: 220 + row: 225 column: 26 end_location: - row: 220 + row: 225 column: 28 fix: edits: [] @@ -176,10 +176,10 @@ expression: diagnostics suggestion: ~ fixable: false location: - row: 221 + row: 226 column: 34 end_location: - row: 221 + row: 226 column: 36 fix: edits: [] @@ -190,10 +190,10 @@ expression: diagnostics suggestion: ~ fixable: false location: - row: 222 + row: 227 column: 61 end_location: - row: 222 + row: 227 column: 66 fix: edits: [] diff --git a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B008_B006_B008.py.snap b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B008_B006_B008.py.snap index 41e45fb9ef..a7f7709dd6 100644 --- a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B008_B006_B008.py.snap +++ b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B008_B006_B008.py.snap @@ -8,10 +8,10 @@ expression: diagnostics suggestion: ~ fixable: false location: - row: 86 + row: 87 column: 60 end_location: - row: 86 + row: 87 column: 68 fix: edits: [] @@ -22,10 +22,10 @@ expression: diagnostics suggestion: ~ fixable: false location: - row: 90 + row: 91 column: 63 end_location: - row: 90 + row: 91 column: 71 fix: edits: [] @@ -36,10 +36,10 @@ expression: diagnostics suggestion: ~ fixable: false location: - row: 94 + row: 95 column: 59 end_location: - row: 94 + row: 95 column: 67 fix: edits: [] @@ -50,10 +50,10 @@ expression: diagnostics suggestion: ~ fixable: false location: - row: 110 + row: 111 column: 38 end_location: - row: 110 + row: 111 column: 49 fix: edits: [] @@ -64,10 +64,10 @@ expression: diagnostics suggestion: ~ fixable: false location: - row: 114 + row: 115 column: 11 end_location: - row: 114 + row: 115 column: 28 fix: edits: [] @@ -78,10 +78,10 @@ expression: diagnostics suggestion: ~ fixable: false location: - row: 118 + row: 119 column: 29 end_location: - row: 118 + row: 119 column: 44 fix: edits: [] @@ -92,10 +92,10 @@ expression: diagnostics suggestion: ~ fixable: false location: - row: 156 + row: 157 column: 33 end_location: - row: 156 + row: 157 column: 47 fix: edits: [] @@ -106,10 +106,10 @@ expression: diagnostics suggestion: ~ fixable: false location: - row: 161 + row: 162 column: 29 end_location: - row: 161 + row: 162 column: 37 fix: edits: [] @@ -120,10 +120,10 @@ expression: diagnostics suggestion: ~ fixable: false location: - row: 165 + row: 166 column: 44 end_location: - row: 165 + row: 166 column: 57 fix: edits: [] @@ -134,10 +134,10 @@ expression: diagnostics suggestion: ~ fixable: false location: - row: 187 + row: 192 column: 20 end_location: - row: 187 + row: 192 column: 28 fix: edits: [] @@ -148,10 +148,10 @@ expression: diagnostics suggestion: ~ fixable: false location: - row: 187 + row: 192 column: 30 end_location: - row: 187 + row: 192 column: 47 fix: edits: [] @@ -162,10 +162,10 @@ expression: diagnostics suggestion: ~ fixable: false location: - row: 193 + row: 198 column: 21 end_location: - row: 193 + row: 198 column: 62 fix: edits: [] @@ -176,10 +176,10 @@ expression: diagnostics suggestion: ~ fixable: false location: - row: 198 + row: 203 column: 18 end_location: - row: 198 + row: 203 column: 59 fix: edits: [] @@ -190,10 +190,10 @@ expression: diagnostics suggestion: ~ fixable: false location: - row: 198 + row: 203 column: 36 end_location: - row: 198 + row: 203 column: 53 fix: edits: []