Compare commits
2 Commits
dhruv/unpa
...
micha/add-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
daa385c1a9 | ||
|
|
01d9312529 |
29
.github/renovate.json5
vendored
29
.github/renovate.json5
vendored
@@ -16,7 +16,7 @@
|
||||
pep621: {
|
||||
// The default for this package manager is to only search for `pyproject.toml` files
|
||||
// found at the repository root: https://docs.renovatebot.com/modules/manager/pep621/#file-matching
|
||||
fileMatch: ["^(python|scripts)/.*pyproject\\.toml$"],
|
||||
managerFilePatterns: ["/^(python|scripts)/.*pyproject\\.toml$/"],
|
||||
},
|
||||
pip_requirements: {
|
||||
// The default for this package manager is to run on all requirements.txt files:
|
||||
@@ -34,12 +34,32 @@
|
||||
npm: {
|
||||
// The default for this package manager is to only search for `package.json` files
|
||||
// found at the repository root: https://docs.renovatebot.com/modules/manager/npm/#file-matching
|
||||
fileMatch: ["^playground/.*package\\.json$"],
|
||||
managerFilePatterns: ["/^playground/.*package\\.json$/"],
|
||||
},
|
||||
customManagers: [
|
||||
{
|
||||
customType: "regex",
|
||||
managerFilePatterns: ["/^dist-workspace\\.toml$/"],
|
||||
matchStrings: [
|
||||
'"(?<depName>actions/[^"]+)" = "(?<currentDigest>[a-f0-9]{40})"\\s*#\\s*(?<currentValue>v[\\d\\.]+).*'
|
||||
],
|
||||
datasourceTemplate: "github-tags",
|
||||
autoReplaceStringTemplate: '"{{depName}}" = "{{newDigest}}" # {{newValue}}"',
|
||||
extractVersionTemplate: "^(?<version>v[\\d\\.]+)$",
|
||||
versioningTemplate: "semver"
|
||||
}
|
||||
],
|
||||
"pre-commit": {
|
||||
enabled: true,
|
||||
},
|
||||
packageRules: [
|
||||
// Ignore GitHub Actions in generated release.yml (managed by cargo-dist)
|
||||
{
|
||||
matchManagers: ["github-actions"],
|
||||
matchFileNames: [".github/workflows/release.yml"],
|
||||
enabled: false,
|
||||
description: "Ignore GitHub Actions in release.yml as it's generated by cargo-dist",
|
||||
},
|
||||
// Pin GitHub Actions to immutable SHAs.
|
||||
{
|
||||
matchDepTypes: ["action"],
|
||||
@@ -106,6 +126,11 @@
|
||||
matchManagers: ["cargo"],
|
||||
matchPackageNames: ["strum"],
|
||||
description: "Weekly update of strum dependencies",
|
||||
},
|
||||
{
|
||||
groupName: "cargo-dist GitHub Actions",
|
||||
matchManagers: ["custom.regex"],
|
||||
description: "Weekly update of GitHub Actions dependencies managed by cargo-dist",
|
||||
}
|
||||
],
|
||||
vulnerabilityAlerts: {
|
||||
|
||||
2
.github/workflows/mypy_primer.yaml
vendored
2
.github/workflows/mypy_primer.yaml
vendored
@@ -70,7 +70,7 @@ jobs:
|
||||
echo "Project selector: $PRIMER_SELECTOR"
|
||||
# Allow the exit code to be 0 or 1, only fail for actual mypy_primer crashes/bugs
|
||||
uvx \
|
||||
--from="git+https://github.com/hauntsaninja/mypy_primer@e5f55447969d33ae3c7ccdb183e2a37101867270" \
|
||||
--from="git+https://github.com/hauntsaninja/mypy_primer@01a7ca325f674433c58e02416a867178d1571128" \
|
||||
mypy_primer \
|
||||
--repo ruff \
|
||||
--type-checker ty \
|
||||
|
||||
18
.github/workflows/release.yml
vendored
18
.github/workflows/release.yml
vendored
@@ -61,7 +61,7 @@ jobs:
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
steps:
|
||||
- uses: actions/checkout@09d2acae674a48949e3602304ab46fd20ae0c42f
|
||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
|
||||
with:
|
||||
persist-credentials: false
|
||||
submodules: recursive
|
||||
@@ -69,9 +69,9 @@ jobs:
|
||||
# we specify bash to get pipefail; it guards against the `curl` command
|
||||
# failing. otherwise `sh` won't catch that `curl` returned non-0
|
||||
shell: bash
|
||||
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/astral-sh/cargo-dist/releases/download/v0.28.5-prerelease.1/cargo-dist-installer.sh | sh"
|
||||
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/astral-sh/cargo-dist/releases/download/v0.28.5-prerelease.3/cargo-dist-installer.sh | sh"
|
||||
- name: Cache dist
|
||||
uses: actions/upload-artifact@6027e3dd177782cd8ab9af838c04fd81a07f1d47
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
|
||||
with:
|
||||
name: cargo-dist-cache
|
||||
path: ~/.cargo/bin/dist
|
||||
@@ -87,7 +87,7 @@ jobs:
|
||||
cat plan-dist-manifest.json
|
||||
echo "manifest=$(jq -c "." plan-dist-manifest.json)" >> "$GITHUB_OUTPUT"
|
||||
- name: "Upload dist-manifest.json"
|
||||
uses: actions/upload-artifact@6027e3dd177782cd8ab9af838c04fd81a07f1d47
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
|
||||
with:
|
||||
name: artifacts-plan-dist-manifest
|
||||
path: plan-dist-manifest.json
|
||||
@@ -124,7 +124,7 @@ jobs:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
BUILD_MANIFEST_NAME: target/distrib/global-dist-manifest.json
|
||||
steps:
|
||||
- uses: actions/checkout@09d2acae674a48949e3602304ab46fd20ae0c42f
|
||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
|
||||
with:
|
||||
persist-credentials: false
|
||||
submodules: recursive
|
||||
@@ -154,7 +154,7 @@ jobs:
|
||||
|
||||
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
|
||||
- name: "Upload artifacts"
|
||||
uses: actions/upload-artifact@6027e3dd177782cd8ab9af838c04fd81a07f1d47
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
|
||||
with:
|
||||
name: artifacts-build-global
|
||||
path: |
|
||||
@@ -175,7 +175,7 @@ jobs:
|
||||
outputs:
|
||||
val: ${{ steps.host.outputs.manifest }}
|
||||
steps:
|
||||
- uses: actions/checkout@09d2acae674a48949e3602304ab46fd20ae0c42f
|
||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
|
||||
with:
|
||||
persist-credentials: false
|
||||
submodules: recursive
|
||||
@@ -201,7 +201,7 @@ jobs:
|
||||
cat dist-manifest.json
|
||||
echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT"
|
||||
- name: "Upload dist-manifest.json"
|
||||
uses: actions/upload-artifact@6027e3dd177782cd8ab9af838c04fd81a07f1d47
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
|
||||
with:
|
||||
# Overwrite the previous copy
|
||||
name: artifacts-dist-manifest
|
||||
@@ -251,7 +251,7 @@ jobs:
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
steps:
|
||||
- uses: actions/checkout@09d2acae674a48949e3602304ab46fd20ae0c42f
|
||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
|
||||
with:
|
||||
persist-credentials: false
|
||||
submodules: recursive
|
||||
|
||||
@@ -36,20 +36,14 @@ impl fmt::Display for AnalyzeSettings {
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, CacheKey)]
|
||||
#[cfg_attr(
|
||||
feature = "serde",
|
||||
derive(serde::Serialize, serde::Deserialize),
|
||||
serde(rename_all = "kebab-case")
|
||||
)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
|
||||
pub enum Direction {
|
||||
/// Construct a map from module to its dependencies (i.e., the modules that it imports).
|
||||
#[default]
|
||||
#[cfg_attr(feature = "serde", serde(alias = "Dependencies"))]
|
||||
Dependencies,
|
||||
/// Construct a map from module to its dependents (i.e., the modules that import it).
|
||||
#[cfg_attr(feature = "serde", serde(alias = "Dependents"))]
|
||||
Dependents,
|
||||
}
|
||||
|
||||
|
||||
@@ -83,13 +83,3 @@ def aliased_parentheses_no_params_multiline():
|
||||
# scope="module"
|
||||
)
|
||||
def my_fixture(): ...
|
||||
|
||||
|
||||
@(pytest.fixture())
|
||||
def outer_paren_fixture_no_params():
|
||||
return 42
|
||||
|
||||
|
||||
@(fixture())
|
||||
def outer_paren_imported_fixture_no_params():
|
||||
return 42
|
||||
|
||||
@@ -88,14 +88,3 @@ class TestClass:
|
||||
# ),
|
||||
)
|
||||
def test_bar(param1, param2): ...
|
||||
|
||||
|
||||
@(pytest.mark.foo())
|
||||
def test_outer_paren_mark_function():
|
||||
pass
|
||||
|
||||
|
||||
class TestClass:
|
||||
@(pytest.mark.foo())
|
||||
def test_method_outer_paren():
|
||||
pass
|
||||
|
||||
@@ -128,16 +128,3 @@ def write_models(directory, Models):
|
||||
pass; \
|
||||
\
|
||||
#
|
||||
|
||||
# Regression tests for: https://github.com/astral-sh/ruff/issues/18209
|
||||
try:
|
||||
1 / 0
|
||||
except ():
|
||||
pass
|
||||
|
||||
|
||||
BaseException = ValueError
|
||||
try:
|
||||
int("a")
|
||||
except BaseException:
|
||||
pass
|
||||
@@ -29,8 +29,3 @@ def foo():
|
||||
dict = {}
|
||||
for country, stars in zip(dict.keys(), dict.values()):
|
||||
...
|
||||
|
||||
|
||||
# https://github.com/astral-sh/ruff/issues/18776
|
||||
flag_stars = {}
|
||||
for country, stars in(zip)(flag_stars.keys(), flag_stars.values()):...
|
||||
|
||||
@@ -85,19 +85,3 @@ import builtins
|
||||
|
||||
for i in builtins.list(nested_tuple): # PERF101
|
||||
pass
|
||||
|
||||
# https://github.com/astral-sh/ruff/issues/18783
|
||||
items = (1, 2, 3)
|
||||
for i in(list)(items):
|
||||
print(i)
|
||||
|
||||
# https://github.com/astral-sh/ruff/issues/18784
|
||||
items = (1, 2, 3)
|
||||
for i in ( # 1
|
||||
list # 2
|
||||
# 3
|
||||
)( # 4
|
||||
items # 5
|
||||
# 6
|
||||
):
|
||||
print(i)
|
||||
|
||||
Binary file not shown.
@@ -129,6 +129,3 @@ blah = dict[{"a": 1}.__delitem__("a")] # OK
|
||||
|
||||
# https://github.com/astral-sh/ruff/issues/14597
|
||||
assert "abc".__str__() == "abc"
|
||||
|
||||
# https://github.com/astral-sh/ruff/issues/18813
|
||||
three = 1 if 1 else(3.0).__str__()
|
||||
|
||||
@@ -71,47 +71,3 @@ if sys.version_info <= (3, 14, 0):
|
||||
|
||||
if sys.version_info <= (3, 14, 15):
|
||||
print()
|
||||
|
||||
# https://github.com/astral-sh/ruff/issues/18165
|
||||
|
||||
if sys.version_info.major >= 3:
|
||||
print("3")
|
||||
else:
|
||||
print("2")
|
||||
|
||||
if sys.version_info.major > 3:
|
||||
print("3")
|
||||
else:
|
||||
print("2")
|
||||
|
||||
if sys.version_info.major <= 3:
|
||||
print("3")
|
||||
else:
|
||||
print("2")
|
||||
|
||||
if sys.version_info.major < 3:
|
||||
print("3")
|
||||
else:
|
||||
print("2")
|
||||
|
||||
if sys.version_info.major == 3:
|
||||
print("3")
|
||||
else:
|
||||
print("2")
|
||||
|
||||
# Semantically incorrect, skip fixing
|
||||
|
||||
if sys.version_info.major[1] > 3:
|
||||
print(3)
|
||||
else:
|
||||
print(2)
|
||||
|
||||
if sys.version_info.major > (3, 13):
|
||||
print(3)
|
||||
else:
|
||||
print(2)
|
||||
|
||||
if sys.version_info.major[:2] > (3, 13):
|
||||
print(3)
|
||||
else:
|
||||
print(2)
|
||||
|
||||
@@ -44,13 +44,6 @@ log(1, math.e)
|
||||
math.log(1, 2.0001)
|
||||
math.log(1, 10.0001)
|
||||
|
||||
# https://github.com/astral-sh/ruff/issues/18747
|
||||
def log():
|
||||
yield math.log((yield), math.e)
|
||||
|
||||
|
||||
def log():
|
||||
yield math.log((yield from x), math.e)
|
||||
|
||||
# see: https://github.com/astral-sh/ruff/issues/18639
|
||||
math.log(1, 10 # comment
|
||||
|
||||
@@ -110,19 +110,3 @@ class ShouldMatchB008RuleOfImmutableTypeAnnotationIgnored:
|
||||
# ignored
|
||||
this_is_fine: int = f()
|
||||
|
||||
|
||||
# Test for:
|
||||
# https://github.com/astral-sh/ruff/issues/17424
|
||||
@dataclass(frozen=True)
|
||||
class C:
|
||||
foo: int = 1
|
||||
|
||||
|
||||
@dataclass
|
||||
class D:
|
||||
c: C = C()
|
||||
|
||||
|
||||
@dataclass
|
||||
class E:
|
||||
c: C = C()
|
||||
@@ -73,55 +73,3 @@ class IntConversionDescriptor:
|
||||
@frozen
|
||||
class InventoryItem:
|
||||
quantity_on_hand: IntConversionDescriptor = IntConversionDescriptor(default=100)
|
||||
|
||||
|
||||
# Test for:
|
||||
# https://github.com/astral-sh/ruff/issues/17424
|
||||
@frozen
|
||||
class C:
|
||||
foo: int = 1
|
||||
|
||||
|
||||
@attr.frozen
|
||||
class D:
|
||||
foo: int = 1
|
||||
|
||||
|
||||
@define
|
||||
class E:
|
||||
c: C = C()
|
||||
d: D = D()
|
||||
|
||||
|
||||
@attr.s
|
||||
class F:
|
||||
foo: int = 1
|
||||
|
||||
|
||||
@attr.mutable
|
||||
class G:
|
||||
foo: int = 1
|
||||
|
||||
|
||||
@attr.attrs
|
||||
class H:
|
||||
f: F = F()
|
||||
g: G = G()
|
||||
|
||||
|
||||
@attr.define
|
||||
class I:
|
||||
f: F = F()
|
||||
g: G = G()
|
||||
|
||||
|
||||
@attr.frozen
|
||||
class J:
|
||||
f: F = F()
|
||||
g: G = G()
|
||||
|
||||
|
||||
@attr.mutable
|
||||
class K:
|
||||
f: F = F()
|
||||
g: G = G()
|
||||
|
||||
@@ -34,7 +34,7 @@ pub(crate) fn bindings(checker: &Checker) {
|
||||
if binding.kind.is_bound_exception()
|
||||
&& binding.is_unused()
|
||||
&& !checker
|
||||
.settings()
|
||||
.settings
|
||||
.dummy_variable_rgx
|
||||
.is_match(binding.name(checker.source()))
|
||||
{
|
||||
@@ -67,7 +67,7 @@ pub(crate) fn bindings(checker: &Checker) {
|
||||
flake8_import_conventions::rules::unconventional_import_alias(
|
||||
checker,
|
||||
binding,
|
||||
&checker.settings().flake8_import_conventions.aliases,
|
||||
&checker.settings.flake8_import_conventions.aliases,
|
||||
);
|
||||
}
|
||||
if checker.is_rule_enabled(Rule::UnaliasedCollectionsAbcSetImport) {
|
||||
|
||||
@@ -76,7 +76,7 @@ pub(crate) fn deferred_scopes(checker: &Checker) {
|
||||
flake8_type_checking::helpers::is_valid_runtime_import(
|
||||
binding,
|
||||
&checker.semantic,
|
||||
&checker.settings().flake8_type_checking,
|
||||
&checker.settings.flake8_type_checking,
|
||||
)
|
||||
})
|
||||
.collect()
|
||||
@@ -139,7 +139,7 @@ pub(crate) fn deferred_scopes(checker: &Checker) {
|
||||
if !shadowed.kind.is_argument() {
|
||||
continue;
|
||||
}
|
||||
if checker.settings().dummy_variable_rgx.is_match(name) {
|
||||
if checker.settings.dummy_variable_rgx.is_match(name) {
|
||||
continue;
|
||||
}
|
||||
let scope = &checker.semantic.scopes[binding.scope];
|
||||
@@ -231,7 +231,7 @@ pub(crate) fn deferred_scopes(checker: &Checker) {
|
||||
| BindingKind::FromImport(..)
|
||||
| BindingKind::SubmoduleImport(..)
|
||||
| BindingKind::FutureImport
|
||||
) && checker.settings().dummy_variable_rgx.is_match(name)
|
||||
) && checker.settings.dummy_variable_rgx.is_match(name)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -402,7 +402,7 @@ pub(crate) fn deferred_scopes(checker: &Checker) {
|
||||
&& binding.is_unused()
|
||||
&& !binding.is_nonlocal()
|
||||
&& !binding.is_global()
|
||||
&& !checker.settings().dummy_variable_rgx.is_match(name)
|
||||
&& !checker.settings.dummy_variable_rgx.is_match(name)
|
||||
&& !matches!(
|
||||
name,
|
||||
"__tracebackhide__"
|
||||
|
||||
@@ -167,7 +167,7 @@ pub(crate) fn definitions(checker: &mut Checker) {
|
||||
if enforce_docstrings || enforce_pydoclint {
|
||||
if pydocstyle::helpers::should_ignore_definition(
|
||||
definition,
|
||||
&checker.settings().pydocstyle,
|
||||
&checker.settings.pydocstyle,
|
||||
&checker.semantic,
|
||||
) {
|
||||
continue;
|
||||
@@ -253,7 +253,7 @@ pub(crate) fn definitions(checker: &mut Checker) {
|
||||
pydocstyle::rules::non_imperative_mood(
|
||||
checker,
|
||||
&docstring,
|
||||
&checker.settings().pydocstyle,
|
||||
&checker.settings.pydocstyle,
|
||||
);
|
||||
}
|
||||
if checker.is_rule_enabled(Rule::SignatureInDocstring) {
|
||||
@@ -292,7 +292,7 @@ pub(crate) fn definitions(checker: &mut Checker) {
|
||||
if enforce_sections || enforce_pydoclint {
|
||||
let section_contexts = pydocstyle::helpers::get_section_contexts(
|
||||
&docstring,
|
||||
checker.settings().pydocstyle.convention(),
|
||||
checker.settings.pydocstyle.convention(),
|
||||
);
|
||||
|
||||
if enforce_sections {
|
||||
@@ -300,7 +300,7 @@ pub(crate) fn definitions(checker: &mut Checker) {
|
||||
checker,
|
||||
&docstring,
|
||||
§ion_contexts,
|
||||
checker.settings().pydocstyle.convention(),
|
||||
checker.settings.pydocstyle.convention(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -310,7 +310,7 @@ pub(crate) fn definitions(checker: &mut Checker) {
|
||||
definition,
|
||||
&docstring,
|
||||
§ion_contexts,
|
||||
checker.settings().pydocstyle.convention(),
|
||||
checker.settings.pydocstyle.convention(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ pub(crate) fn except_handler(except_handler: &ExceptHandler, checker: &Checker)
|
||||
except_handler,
|
||||
type_.as_deref(),
|
||||
body,
|
||||
checker.settings().flake8_bandit.check_typed_exception,
|
||||
checker.settings.flake8_bandit.check_typed_exception,
|
||||
);
|
||||
}
|
||||
if checker.is_rule_enabled(Rule::TryExceptContinue) {
|
||||
@@ -50,7 +50,7 @@ pub(crate) fn except_handler(except_handler: &ExceptHandler, checker: &Checker)
|
||||
except_handler,
|
||||
type_.as_deref(),
|
||||
body,
|
||||
checker.settings().flake8_bandit.check_typed_exception,
|
||||
checker.settings.flake8_bandit.check_typed_exception,
|
||||
);
|
||||
}
|
||||
if checker.is_rule_enabled(Rule::ExceptWithEmptyTuple) {
|
||||
|
||||
@@ -35,7 +35,7 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) {
|
||||
&& checker.target_version() < PythonVersion::PY310
|
||||
&& checker.target_version() >= PythonVersion::PY37
|
||||
&& checker.semantic.in_annotation()
|
||||
&& !checker.settings().pyupgrade.keep_runtime_typing
|
||||
&& !checker.settings.pyupgrade.keep_runtime_typing
|
||||
{
|
||||
flake8_future_annotations::rules::future_rewritable_type_annotation(
|
||||
checker, value,
|
||||
@@ -51,7 +51,7 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) {
|
||||
|| (checker.target_version() >= PythonVersion::PY37
|
||||
&& checker.semantic.future_annotations_or_stub()
|
||||
&& checker.semantic.in_annotation()
|
||||
&& !checker.settings().pyupgrade.keep_runtime_typing)
|
||||
&& !checker.settings.pyupgrade.keep_runtime_typing)
|
||||
{
|
||||
pyupgrade::rules::non_pep604_annotation(checker, expr, slice, operator);
|
||||
}
|
||||
@@ -288,7 +288,7 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) {
|
||||
&& checker.target_version() < PythonVersion::PY39
|
||||
&& checker.target_version() >= PythonVersion::PY37
|
||||
&& checker.semantic.in_annotation()
|
||||
&& !checker.settings().pyupgrade.keep_runtime_typing
|
||||
&& !checker.settings.pyupgrade.keep_runtime_typing
|
||||
{
|
||||
flake8_future_annotations::rules::future_rewritable_type_annotation(checker, expr);
|
||||
}
|
||||
@@ -299,7 +299,7 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) {
|
||||
|| (checker.target_version() >= PythonVersion::PY37
|
||||
&& checker.semantic.future_annotations_or_stub()
|
||||
&& checker.semantic.in_annotation()
|
||||
&& !checker.settings().pyupgrade.keep_runtime_typing)
|
||||
&& !checker.settings.pyupgrade.keep_runtime_typing)
|
||||
{
|
||||
pyupgrade::rules::use_pep585_annotation(
|
||||
checker,
|
||||
@@ -395,7 +395,7 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) {
|
||||
&& checker.target_version() < PythonVersion::PY39
|
||||
&& checker.target_version() >= PythonVersion::PY37
|
||||
&& checker.semantic.in_annotation()
|
||||
&& !checker.settings().pyupgrade.keep_runtime_typing
|
||||
&& !checker.settings.pyupgrade.keep_runtime_typing
|
||||
{
|
||||
flake8_future_annotations::rules::future_rewritable_type_annotation(
|
||||
checker, expr,
|
||||
@@ -408,7 +408,7 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) {
|
||||
|| (checker.target_version() >= PythonVersion::PY37
|
||||
&& checker.semantic.future_annotations_or_stub()
|
||||
&& checker.semantic.in_annotation()
|
||||
&& !checker.settings().pyupgrade.keep_runtime_typing)
|
||||
&& !checker.settings.pyupgrade.keep_runtime_typing)
|
||||
{
|
||||
pyupgrade::rules::use_pep585_annotation(checker, expr, &replacement);
|
||||
}
|
||||
@@ -841,7 +841,7 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) {
|
||||
flake8_comprehensions::rules::unnecessary_collection_call(
|
||||
checker,
|
||||
call,
|
||||
&checker.settings().flake8_comprehensions,
|
||||
&checker.settings.flake8_comprehensions,
|
||||
);
|
||||
}
|
||||
if checker.is_rule_enabled(Rule::UnnecessaryLiteralWithinTupleCall) {
|
||||
@@ -1006,7 +1006,7 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) {
|
||||
Rule::PrintfInGetTextFuncCall,
|
||||
]) && flake8_gettext::is_gettext_func_call(
|
||||
func,
|
||||
&checker.settings().flake8_gettext.functions_names,
|
||||
&checker.settings.flake8_gettext.functions_names,
|
||||
) {
|
||||
if checker.is_rule_enabled(Rule::FStringInGetTextFuncCall) {
|
||||
flake8_gettext::rules::f_string_in_gettext_func_call(checker, args);
|
||||
|
||||
@@ -132,7 +132,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) {
|
||||
stmt,
|
||||
name,
|
||||
decorator_list,
|
||||
&checker.settings().pep8_naming.ignore_names,
|
||||
&checker.settings.pep8_naming.ignore_names,
|
||||
&checker.semantic,
|
||||
);
|
||||
}
|
||||
@@ -189,7 +189,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) {
|
||||
checker.semantic.current_scope(),
|
||||
stmt,
|
||||
name,
|
||||
&checker.settings().pep8_naming.ignore_names,
|
||||
&checker.settings.pep8_naming.ignore_names,
|
||||
);
|
||||
}
|
||||
if checker.is_rule_enabled(Rule::GlobalStatement) {
|
||||
@@ -240,7 +240,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) {
|
||||
stmt,
|
||||
name,
|
||||
body,
|
||||
checker.settings().mccabe.max_complexity,
|
||||
checker.settings.mccabe.max_complexity,
|
||||
);
|
||||
}
|
||||
if checker.is_rule_enabled(Rule::HardcodedPasswordDefault) {
|
||||
@@ -265,7 +265,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) {
|
||||
checker,
|
||||
stmt,
|
||||
body,
|
||||
checker.settings().pylint.max_returns,
|
||||
checker.settings.pylint.max_returns,
|
||||
);
|
||||
}
|
||||
if checker.is_rule_enabled(Rule::TooManyBranches) {
|
||||
@@ -273,7 +273,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) {
|
||||
checker,
|
||||
stmt,
|
||||
body,
|
||||
checker.settings().pylint.max_branches,
|
||||
checker.settings.pylint.max_branches,
|
||||
);
|
||||
}
|
||||
if checker.is_rule_enabled(Rule::TooManyStatements) {
|
||||
@@ -281,7 +281,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) {
|
||||
checker,
|
||||
stmt,
|
||||
body,
|
||||
checker.settings().pylint.max_statements,
|
||||
checker.settings.pylint.max_statements,
|
||||
);
|
||||
}
|
||||
if checker.any_rule_enabled(&[
|
||||
@@ -431,7 +431,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) {
|
||||
pylint::rules::too_many_public_methods(
|
||||
checker,
|
||||
class_def,
|
||||
checker.settings().pylint.max_public_methods,
|
||||
checker.settings.pylint.max_public_methods,
|
||||
);
|
||||
}
|
||||
if checker.is_rule_enabled(Rule::GlobalStatement) {
|
||||
@@ -459,7 +459,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) {
|
||||
checker,
|
||||
stmt,
|
||||
name,
|
||||
&checker.settings().pep8_naming.ignore_names,
|
||||
&checker.settings.pep8_naming.ignore_names,
|
||||
);
|
||||
}
|
||||
if checker.is_rule_enabled(Rule::ErrorSuffixOnExceptionName) {
|
||||
@@ -468,7 +468,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) {
|
||||
stmt,
|
||||
arguments.as_deref(),
|
||||
name,
|
||||
&checker.settings().pep8_naming.ignore_names,
|
||||
&checker.settings.pep8_naming.ignore_names,
|
||||
);
|
||||
}
|
||||
if !checker.source_type.is_stub() {
|
||||
@@ -646,7 +646,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) {
|
||||
asname,
|
||||
alias,
|
||||
stmt,
|
||||
&checker.settings().pep8_naming.ignore_names,
|
||||
&checker.settings.pep8_naming.ignore_names,
|
||||
);
|
||||
}
|
||||
if checker.is_rule_enabled(Rule::LowercaseImportedAsNonLowercase) {
|
||||
@@ -656,7 +656,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) {
|
||||
asname,
|
||||
alias,
|
||||
stmt,
|
||||
&checker.settings().pep8_naming.ignore_names,
|
||||
&checker.settings.pep8_naming.ignore_names,
|
||||
);
|
||||
}
|
||||
if checker.is_rule_enabled(Rule::CamelcaseImportedAsLowercase) {
|
||||
@@ -666,7 +666,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) {
|
||||
asname,
|
||||
alias,
|
||||
stmt,
|
||||
&checker.settings().pep8_naming.ignore_names,
|
||||
&checker.settings.pep8_naming.ignore_names,
|
||||
);
|
||||
}
|
||||
if checker.is_rule_enabled(Rule::CamelcaseImportedAsConstant) {
|
||||
@@ -676,7 +676,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) {
|
||||
asname,
|
||||
alias,
|
||||
stmt,
|
||||
&checker.settings().pep8_naming.ignore_names,
|
||||
&checker.settings.pep8_naming.ignore_names,
|
||||
);
|
||||
}
|
||||
if checker.is_rule_enabled(Rule::CamelcaseImportedAsAcronym) {
|
||||
@@ -692,7 +692,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) {
|
||||
stmt,
|
||||
&alias.name,
|
||||
asname,
|
||||
&checker.settings().flake8_import_conventions.banned_aliases,
|
||||
&checker.settings.flake8_import_conventions.banned_aliases,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -854,7 +854,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) {
|
||||
level,
|
||||
module,
|
||||
checker.module.qualified_name(),
|
||||
checker.settings().flake8_tidy_imports.ban_relative_imports,
|
||||
checker.settings.flake8_tidy_imports.ban_relative_imports,
|
||||
);
|
||||
}
|
||||
if checker.is_rule_enabled(Rule::Debugger) {
|
||||
@@ -869,7 +869,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) {
|
||||
stmt,
|
||||
&qualified_name,
|
||||
asname,
|
||||
&checker.settings().flake8_import_conventions.banned_aliases,
|
||||
&checker.settings.flake8_import_conventions.banned_aliases,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -881,7 +881,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) {
|
||||
asname,
|
||||
alias,
|
||||
stmt,
|
||||
&checker.settings().pep8_naming.ignore_names,
|
||||
&checker.settings.pep8_naming.ignore_names,
|
||||
);
|
||||
}
|
||||
if checker.is_rule_enabled(Rule::LowercaseImportedAsNonLowercase) {
|
||||
@@ -891,7 +891,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) {
|
||||
asname,
|
||||
alias,
|
||||
stmt,
|
||||
&checker.settings().pep8_naming.ignore_names,
|
||||
&checker.settings.pep8_naming.ignore_names,
|
||||
);
|
||||
}
|
||||
if checker.is_rule_enabled(Rule::CamelcaseImportedAsLowercase) {
|
||||
@@ -901,7 +901,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) {
|
||||
asname,
|
||||
alias,
|
||||
stmt,
|
||||
&checker.settings().pep8_naming.ignore_names,
|
||||
&checker.settings.pep8_naming.ignore_names,
|
||||
);
|
||||
}
|
||||
if checker.is_rule_enabled(Rule::CamelcaseImportedAsConstant) {
|
||||
@@ -911,7 +911,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) {
|
||||
asname,
|
||||
alias,
|
||||
stmt,
|
||||
&checker.settings().pep8_naming.ignore_names,
|
||||
&checker.settings.pep8_naming.ignore_names,
|
||||
);
|
||||
}
|
||||
if checker.is_rule_enabled(Rule::CamelcaseImportedAsAcronym) {
|
||||
@@ -947,7 +947,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) {
|
||||
checker,
|
||||
stmt,
|
||||
&helpers::format_import_from(level, module),
|
||||
&checker.settings().flake8_import_conventions.banned_from,
|
||||
&checker.settings.flake8_import_conventions.banned_from,
|
||||
);
|
||||
}
|
||||
if checker.is_rule_enabled(Rule::ByteStringUsage) {
|
||||
|
||||
@@ -34,7 +34,7 @@ pub(crate) fn string_like(string_like: StringLike, checker: &Checker) {
|
||||
flake8_quotes::rules::unnecessary_escaped_quote(checker, string_like);
|
||||
}
|
||||
if checker.is_rule_enabled(Rule::AvoidableEscapedQuote)
|
||||
&& checker.settings().flake8_quotes.avoid_escape
|
||||
&& checker.settings.flake8_quotes.avoid_escape
|
||||
{
|
||||
flake8_quotes::rules::avoidable_escaped_quote(checker, string_like);
|
||||
}
|
||||
|
||||
@@ -207,6 +207,8 @@ pub(crate) struct Checker<'a> {
|
||||
/// The [`NoqaMapping`] for the current analysis (i.e., the mapping from line number to
|
||||
/// suppression commented line number).
|
||||
noqa_line_for: &'a NoqaMapping,
|
||||
/// The [`LinterSettings`] for the current analysis, including the enabled rules.
|
||||
pub(crate) settings: &'a LinterSettings,
|
||||
/// The [`Locator`] for the current file, which enables extraction of source code from byte
|
||||
/// offsets.
|
||||
locator: &'a Locator<'a>,
|
||||
@@ -258,12 +260,13 @@ impl<'a> Checker<'a> {
|
||||
notebook_index: Option<&'a NotebookIndex>,
|
||||
target_version: TargetVersion,
|
||||
context: &'a LintContext<'a>,
|
||||
) -> Self {
|
||||
) -> Checker<'a> {
|
||||
let semantic = SemanticModel::new(&settings.typing_modules, path, module);
|
||||
Self {
|
||||
parsed,
|
||||
parsed_type_annotation: None,
|
||||
parsed_annotations_cache: ParsedAnnotationsCache::new(parsed_annotations_arena),
|
||||
settings,
|
||||
noqa_line_for,
|
||||
noqa,
|
||||
path,
|
||||
@@ -461,11 +464,6 @@ impl<'a> Checker<'a> {
|
||||
&self.semantic
|
||||
}
|
||||
|
||||
/// The [`LinterSettings`] for the current analysis, including the enabled rules.
|
||||
pub(crate) const fn settings(&self) -> &'a LinterSettings {
|
||||
self.context.settings
|
||||
}
|
||||
|
||||
/// The [`Path`] to the file under analysis.
|
||||
pub(crate) const fn path(&self) -> &'a Path {
|
||||
self.path
|
||||
@@ -578,7 +576,7 @@ impl<'a> Checker<'a> {
|
||||
) -> Option<TypingImporter<'b, 'a>> {
|
||||
let source_module = if self.target_version() >= version_added_to_typing {
|
||||
"typing"
|
||||
} else if !self.settings().typing_extensions {
|
||||
} else if !self.settings.typing_extensions {
|
||||
return None;
|
||||
} else {
|
||||
"typing_extensions"
|
||||
@@ -1056,7 +1054,7 @@ impl<'a> Visitor<'a> for Checker<'a> {
|
||||
let annotation = AnnotationContext::from_function(
|
||||
function_def,
|
||||
&self.semantic,
|
||||
self.settings(),
|
||||
self.settings,
|
||||
self.target_version(),
|
||||
);
|
||||
|
||||
@@ -1258,7 +1256,7 @@ impl<'a> Visitor<'a> for Checker<'a> {
|
||||
}) => {
|
||||
match AnnotationContext::from_model(
|
||||
&self.semantic,
|
||||
self.settings(),
|
||||
self.settings,
|
||||
self.target_version(),
|
||||
) {
|
||||
AnnotationContext::RuntimeRequired => {
|
||||
@@ -1870,8 +1868,8 @@ impl<'a> Visitor<'a> for Checker<'a> {
|
||||
match typing::match_annotated_subscript(
|
||||
value,
|
||||
&self.semantic,
|
||||
self.settings().typing_modules.iter().map(String::as_str),
|
||||
&self.settings().pyflakes.extend_generics,
|
||||
self.settings.typing_modules.iter().map(String::as_str),
|
||||
&self.settings.pyflakes.extend_generics,
|
||||
) {
|
||||
// Ex) Literal["Class"]
|
||||
Some(typing::SubscriptKind::Literal) => {
|
||||
@@ -2478,7 +2476,6 @@ impl<'a> Checker<'a> {
|
||||
|
||||
fn bind_builtins(&mut self) {
|
||||
let target_version = self.target_version();
|
||||
let settings = self.settings();
|
||||
let mut bind_builtin = |builtin| {
|
||||
// Add the builtin to the scope.
|
||||
let binding_id = self.semantic.push_builtin();
|
||||
@@ -2492,7 +2489,7 @@ impl<'a> Checker<'a> {
|
||||
for builtin in MAGIC_GLOBALS {
|
||||
bind_builtin(builtin);
|
||||
}
|
||||
for builtin in &settings.builtins {
|
||||
for builtin in &self.settings.builtins {
|
||||
bind_builtin(builtin);
|
||||
}
|
||||
}
|
||||
@@ -2966,7 +2963,7 @@ impl<'a> Checker<'a> {
|
||||
}
|
||||
} else {
|
||||
if self.is_rule_enabled(Rule::UndefinedExport) {
|
||||
if is_undefined_export_in_dunder_init_enabled(self.settings())
|
||||
if is_undefined_export_in_dunder_init_enabled(self.settings)
|
||||
|| !self.path.ends_with("__init__.py")
|
||||
{
|
||||
self.report_diagnostic(
|
||||
@@ -3118,6 +3115,7 @@ pub(crate) struct LintContext<'a> {
|
||||
diagnostics: RefCell<Vec<OldDiagnostic>>,
|
||||
source_file: SourceFile,
|
||||
rules: RuleTable,
|
||||
#[expect(unused, reason = "TODO(brent) use this instead of Checker::settings")]
|
||||
settings: &'a LinterSettings,
|
||||
}
|
||||
|
||||
|
||||
@@ -648,9 +648,9 @@ pub(crate) fn definition(
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if !(checker.settings().flake8_annotations.suppress_dummy_args
|
||||
if !(checker.settings.flake8_annotations.suppress_dummy_args
|
||||
&& checker
|
||||
.settings()
|
||||
.settings
|
||||
.dummy_variable_rgx
|
||||
.is_match(parameter.name()))
|
||||
{
|
||||
@@ -670,15 +670,15 @@ pub(crate) fn definition(
|
||||
if let Some(arg) = ¶meters.vararg {
|
||||
if let Some(expr) = &arg.annotation {
|
||||
has_any_typed_arg = true;
|
||||
if !checker.settings().flake8_annotations.allow_star_arg_any {
|
||||
if !checker.settings.flake8_annotations.allow_star_arg_any {
|
||||
if checker.is_rule_enabled(Rule::AnyType) && !is_overridden {
|
||||
let name = &arg.name;
|
||||
check_dynamically_typed(checker, expr, || format!("*{name}"), &mut diagnostics);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if !(checker.settings().flake8_annotations.suppress_dummy_args
|
||||
&& checker.settings().dummy_variable_rgx.is_match(&arg.name))
|
||||
if !(checker.settings.flake8_annotations.suppress_dummy_args
|
||||
&& checker.settings.dummy_variable_rgx.is_match(&arg.name))
|
||||
{
|
||||
if checker.is_rule_enabled(Rule::MissingTypeArgs) {
|
||||
diagnostics.push(checker.report_diagnostic(
|
||||
@@ -696,7 +696,7 @@ pub(crate) fn definition(
|
||||
if let Some(arg) = ¶meters.kwarg {
|
||||
if let Some(expr) = &arg.annotation {
|
||||
has_any_typed_arg = true;
|
||||
if !checker.settings().flake8_annotations.allow_star_arg_any {
|
||||
if !checker.settings.flake8_annotations.allow_star_arg_any {
|
||||
if checker.is_rule_enabled(Rule::AnyType) && !is_overridden {
|
||||
let name = &arg.name;
|
||||
check_dynamically_typed(
|
||||
@@ -708,8 +708,8 @@ pub(crate) fn definition(
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if !(checker.settings().flake8_annotations.suppress_dummy_args
|
||||
&& checker.settings().dummy_variable_rgx.is_match(&arg.name))
|
||||
if !(checker.settings.flake8_annotations.suppress_dummy_args
|
||||
&& checker.settings.dummy_variable_rgx.is_match(&arg.name))
|
||||
{
|
||||
if checker.is_rule_enabled(Rule::MissingTypeKwargs) {
|
||||
diagnostics.push(checker.report_diagnostic(
|
||||
@@ -732,11 +732,7 @@ pub(crate) fn definition(
|
||||
} else if !(
|
||||
// Allow omission of return annotation if the function only returns `None`
|
||||
// (explicitly or implicitly).
|
||||
checker
|
||||
.settings()
|
||||
.flake8_annotations
|
||||
.suppress_none_returning
|
||||
&& is_none_returning(body)
|
||||
checker.settings.flake8_annotations.suppress_none_returning && is_none_returning(body)
|
||||
) {
|
||||
if is_method && visibility::is_classmethod(decorator_list, checker.semantic()) {
|
||||
if checker.is_rule_enabled(Rule::MissingReturnTypeClassMethod) {
|
||||
@@ -794,7 +790,7 @@ pub(crate) fn definition(
|
||||
// Allow omission of return annotation in `__init__` functions, as long as at
|
||||
// least one argument is typed.
|
||||
if checker.is_rule_enabled(Rule::MissingReturnTypeSpecialMethod) {
|
||||
if !(checker.settings().flake8_annotations.mypy_init_return && has_any_typed_arg) {
|
||||
if !(checker.settings.flake8_annotations.mypy_init_return && has_any_typed_arg) {
|
||||
let mut diagnostic = checker.report_diagnostic(
|
||||
MissingReturnTypeSpecialMethod {
|
||||
name: name.to_string(),
|
||||
@@ -905,7 +901,7 @@ pub(crate) fn definition(
|
||||
|
||||
// If settings say so, don't report any of the
|
||||
// diagnostics gathered here if there were no type annotations at all.
|
||||
let diagnostics_enabled = !checker.settings().flake8_annotations.ignore_fully_untyped
|
||||
let diagnostics_enabled = !checker.settings.flake8_annotations.ignore_fully_untyped
|
||||
|| has_any_typed_arg
|
||||
|| has_typed_return
|
||||
|| (is_method
|
||||
|
||||
@@ -84,7 +84,7 @@ pub(crate) fn hardcoded_tmp_directory(checker: &Checker, string: StringLike) {
|
||||
|
||||
fn check(checker: &Checker, value: &str, range: TextRange) {
|
||||
if !checker
|
||||
.settings()
|
||||
.settings
|
||||
.flake8_bandit
|
||||
.hardcoded_tmp_directory
|
||||
.iter()
|
||||
|
||||
@@ -936,7 +936,7 @@ pub(crate) fn suspicious_function_call(checker: &Checker, call: &ExprCall) {
|
||||
}
|
||||
|
||||
pub(crate) fn suspicious_function_reference(checker: &Checker, func: &Expr) {
|
||||
if !is_suspicious_function_reference_enabled(checker.settings()) {
|
||||
if !is_suspicious_function_reference_enabled(checker.settings) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1270,7 +1270,7 @@ fn suspicious_function(
|
||||
/// S308
|
||||
pub(crate) fn suspicious_function_decorator(checker: &Checker, decorator: &Decorator) {
|
||||
// In preview mode, references are handled collectively by `suspicious_function_reference`
|
||||
if !is_suspicious_function_reference_enabled(checker.settings()) {
|
||||
if !is_suspicious_function_reference_enabled(checker.settings) {
|
||||
suspicious_function(checker, &decorator.expression, None, decorator.range);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ impl Violation for UnsafeMarkupUse {
|
||||
/// S704
|
||||
pub(crate) fn unsafe_markup_call(checker: &Checker, call: &ExprCall) {
|
||||
if checker
|
||||
.settings()
|
||||
.settings
|
||||
.flake8_bandit
|
||||
.extend_markup_names
|
||||
.is_empty()
|
||||
@@ -100,7 +100,7 @@ pub(crate) fn unsafe_markup_call(checker: &Checker, call: &ExprCall) {
|
||||
return;
|
||||
}
|
||||
|
||||
if !is_unsafe_call(call, checker.semantic(), checker.settings()) {
|
||||
if !is_unsafe_call(call, checker.semantic(), checker.settings) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ pub(crate) fn unsafe_markup_call(checker: &Checker, call: &ExprCall) {
|
||||
return;
|
||||
};
|
||||
|
||||
if !is_markup_call(&qualified_name, checker.settings()) {
|
||||
if !is_markup_call(&qualified_name, checker.settings) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ pub(crate) fn blind_except(
|
||||
}
|
||||
|
||||
// If the exception is logged, don't flag an error.
|
||||
let mut visitor = LogExceptionVisitor::new(semantic, &checker.settings().logger_objects);
|
||||
let mut visitor = LogExceptionVisitor::new(semantic, &checker.settings.logger_objects);
|
||||
visitor.visit_body(body);
|
||||
if visitor.seen() {
|
||||
return;
|
||||
|
||||
@@ -185,7 +185,7 @@ pub(super) fn allow_boolean_trap(call: &ast::ExprCall, checker: &Checker) -> boo
|
||||
}
|
||||
|
||||
// If the call is explicitly allowed by the user, then the boolean trap is allowed.
|
||||
if is_user_allowed_func_call(call, checker.semantic(), checker.settings()) {
|
||||
if is_user_allowed_func_call(call, checker.semantic(), checker.settings) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -88,8 +88,8 @@ pub(crate) fn cached_instance_method(checker: &Checker, function_def: &ast::Stmt
|
||||
&function_def.decorator_list,
|
||||
scope,
|
||||
checker.semantic(),
|
||||
&checker.settings().pep8_naming.classmethod_decorators,
|
||||
&checker.settings().pep8_naming.staticmethod_decorators,
|
||||
&checker.settings.pep8_naming.classmethod_decorators,
|
||||
&checker.settings.pep8_naming.staticmethod_decorators,
|
||||
);
|
||||
if !matches!(type_, function_type::FunctionType::Method) {
|
||||
return;
|
||||
|
||||
@@ -132,7 +132,7 @@ impl Visitor<'_> for ArgumentDefaultVisitor<'_, '_> {
|
||||
pub(crate) fn function_call_in_argument_default(checker: &Checker, parameters: &Parameters) {
|
||||
// Map immutable calls to (module, member) format.
|
||||
let extend_immutable_calls: Vec<QualifiedName> = checker
|
||||
.settings()
|
||||
.settings
|
||||
.flake8_bugbear
|
||||
.extend_immutable_calls
|
||||
.iter()
|
||||
|
||||
@@ -105,7 +105,7 @@ pub(crate) fn mutable_argument_default(checker: &Checker, function_def: &ast::St
|
||||
};
|
||||
|
||||
let extend_immutable_calls: Vec<QualifiedName> = checker
|
||||
.settings()
|
||||
.settings
|
||||
.flake8_bugbear
|
||||
.extend_immutable_calls
|
||||
.iter()
|
||||
|
||||
@@ -82,7 +82,7 @@ pub(crate) fn mutable_contextvar_default(checker: &Checker, call: &ast::ExprCall
|
||||
};
|
||||
|
||||
let extend_immutable_calls: Vec<QualifiedName> = checker
|
||||
.settings()
|
||||
.settings
|
||||
.flake8_bugbear
|
||||
.extend_immutable_calls
|
||||
.iter()
|
||||
|
||||
@@ -93,7 +93,7 @@ pub(crate) fn unused_loop_control_variable(checker: &Checker, stmt_for: &ast::St
|
||||
|
||||
for (name, expr) in control_names {
|
||||
// Ignore names that are already underscore-prefixed.
|
||||
if checker.settings().dummy_variable_rgx.is_match(name) {
|
||||
if checker.settings.dummy_variable_rgx.is_match(name) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ pub(crate) fn unused_loop_control_variable(checker: &Checker, stmt_for: &ast::St
|
||||
// violation in the next pass.
|
||||
let rename = format!("_{name}");
|
||||
let rename = checker
|
||||
.settings()
|
||||
.settings
|
||||
.dummy_variable_rgx
|
||||
.is_match(rename.as_str())
|
||||
.then_some(rename);
|
||||
|
||||
@@ -66,7 +66,7 @@ pub(crate) fn builtin_argument_shadowing(checker: &Checker, parameter: &Paramete
|
||||
if shadows_builtin(
|
||||
parameter.name(),
|
||||
checker.source_type,
|
||||
&checker.settings().flake8_builtins.ignorelist,
|
||||
&checker.settings.flake8_builtins.ignorelist,
|
||||
checker.target_version(),
|
||||
) {
|
||||
// Ignore parameters in lambda expressions.
|
||||
|
||||
@@ -97,7 +97,7 @@ pub(crate) fn builtin_attribute_shadowing(
|
||||
if shadows_builtin(
|
||||
name,
|
||||
checker.source_type,
|
||||
&checker.settings().flake8_builtins.ignorelist,
|
||||
&checker.settings.flake8_builtins.ignorelist,
|
||||
checker.target_version(),
|
||||
) {
|
||||
// Ignore explicit overrides.
|
||||
|
||||
@@ -59,7 +59,7 @@ pub(crate) fn builtin_import_shadowing(checker: &Checker, alias: &Alias) {
|
||||
if shadows_builtin(
|
||||
name.as_str(),
|
||||
checker.source_type,
|
||||
&checker.settings().flake8_builtins.ignorelist,
|
||||
&checker.settings.flake8_builtins.ignorelist,
|
||||
checker.target_version(),
|
||||
) {
|
||||
checker.report_diagnostic(
|
||||
|
||||
@@ -43,7 +43,7 @@ pub(crate) fn builtin_lambda_argument_shadowing(checker: &Checker, lambda: &Expr
|
||||
if shadows_builtin(
|
||||
name,
|
||||
checker.source_type,
|
||||
&checker.settings().flake8_builtins.ignorelist,
|
||||
&checker.settings.flake8_builtins.ignorelist,
|
||||
checker.target_version(),
|
||||
) {
|
||||
checker.report_diagnostic(
|
||||
|
||||
@@ -70,7 +70,7 @@ pub(crate) fn builtin_variable_shadowing(checker: &Checker, name: &str, range: T
|
||||
if shadows_builtin(
|
||||
name,
|
||||
checker.source_type,
|
||||
&checker.settings().flake8_builtins.ignorelist,
|
||||
&checker.settings.flake8_builtins.ignorelist,
|
||||
checker.target_version(),
|
||||
) {
|
||||
checker.report_diagnostic(
|
||||
|
||||
@@ -126,7 +126,7 @@ pub(crate) fn unnecessary_comprehension_in_call(
|
||||
if !(matches!(
|
||||
builtin_function,
|
||||
SupportedBuiltins::Any | SupportedBuiltins::All
|
||||
) || (is_comprehension_with_min_max_sum_enabled(checker.settings())
|
||||
) || (is_comprehension_with_min_max_sum_enabled(checker.settings)
|
||||
&& matches!(
|
||||
builtin_function,
|
||||
SupportedBuiltins::Sum | SupportedBuiltins::Min | SupportedBuiltins::Max
|
||||
|
||||
@@ -101,7 +101,7 @@ pub(crate) fn unnecessary_literal_within_tuple_call(
|
||||
let argument_kind = match argument {
|
||||
Expr::Tuple(_) => TupleLiteralKind::Tuple,
|
||||
Expr::List(_) => TupleLiteralKind::List,
|
||||
Expr::ListComp(_) if is_check_comprehensions_in_tuple_call_enabled(checker.settings()) => {
|
||||
Expr::ListComp(_) if is_check_comprehensions_in_tuple_call_enabled(checker.settings) => {
|
||||
TupleLiteralKind::ListComp
|
||||
}
|
||||
_ => return,
|
||||
|
||||
@@ -186,7 +186,7 @@ pub(crate) fn string_in_exception(checker: &Checker, stmt: &Stmt, exc: &Expr) {
|
||||
// Check for string literals.
|
||||
Expr::StringLiteral(ast::ExprStringLiteral { value: string, .. }) => {
|
||||
if checker.is_rule_enabled(Rule::RawStringInException) {
|
||||
if string.len() >= checker.settings().flake8_errmsg.max_string_length {
|
||||
if string.len() >= checker.settings.flake8_errmsg.max_string_length {
|
||||
let mut diagnostic =
|
||||
checker.report_diagnostic(RawStringInException, first.range());
|
||||
if let Some(indentation) =
|
||||
|
||||
@@ -52,11 +52,7 @@ pub(crate) fn explicit(checker: &Checker, expr: &Expr) {
|
||||
// strings that span multiple lines even if this rule is enabled. Otherwise, there's no way
|
||||
// for the user to write multiline strings, and that setting is "more explicit" than this rule
|
||||
// being enabled.
|
||||
if !checker
|
||||
.settings()
|
||||
.flake8_implicit_str_concat
|
||||
.allow_multiline
|
||||
{
|
||||
if !checker.settings.flake8_implicit_str_concat.allow_multiline {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,10 +36,6 @@ use crate::{Edit, Fix, FixAvailability, Violation};
|
||||
/// logger = logging.getLogger(__name__)
|
||||
/// ```
|
||||
///
|
||||
/// ## Fix safety
|
||||
/// This fix is always unsafe, as changing from `Logger` to `getLogger`
|
||||
/// changes program behavior by will adding the logger to the logging tree.
|
||||
///
|
||||
/// [Logger Objects]: https://docs.python.org/3/library/logging.html#logger-objects
|
||||
#[derive(ViolationMetadata)]
|
||||
pub(crate) struct DirectLoggerInstantiation;
|
||||
|
||||
@@ -68,7 +68,7 @@ pub(crate) fn exc_info_outside_except_handler(checker: &Checker, call: &ExprCall
|
||||
|
||||
match &*call.func {
|
||||
func @ Expr::Attribute(ExprAttribute { attr, .. }) => {
|
||||
if !is_logger_candidate(func, semantic, &checker.settings().logger_objects) {
|
||||
if !is_logger_candidate(func, semantic, &checker.settings.logger_objects) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ pub(crate) fn exception_without_exc_info(checker: &Checker, call: &ExprCall) {
|
||||
if !logging::is_logger_candidate(
|
||||
&call.func,
|
||||
checker.semantic(),
|
||||
&checker.settings().logger_objects,
|
||||
&checker.settings.logger_objects,
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -39,10 +39,6 @@ use crate::{Edit, Fix, FixAvailability, Violation};
|
||||
/// logger = logging.getLogger(__name__)
|
||||
/// ```
|
||||
///
|
||||
/// ## Fix safety
|
||||
/// This fix is always unsafe, as changing the arguments to `getLogger` can change the
|
||||
/// received logger object, and thus program behavior.
|
||||
///
|
||||
/// [logging documentation]: https://docs.python.org/3/library/logging.html#logger-objects
|
||||
#[derive(ViolationMetadata)]
|
||||
pub(crate) struct InvalidGetLoggerArgument;
|
||||
|
||||
@@ -69,7 +69,7 @@ pub(crate) fn log_exception_outside_except_handler(checker: &Checker, call: &Exp
|
||||
|
||||
let fix = match &*call.func {
|
||||
func @ Expr::Attribute(ExprAttribute { attr, .. }) => {
|
||||
let logger_objects = &checker.settings().logger_objects;
|
||||
let logger_objects = &checker.settings.logger_objects;
|
||||
|
||||
if !logging::is_logger_candidate(func, semantic, logger_objects) {
|
||||
return;
|
||||
|
||||
@@ -147,7 +147,7 @@ pub(crate) fn logging_call(checker: &Checker, call: &ast::ExprCall) {
|
||||
if !logging::is_logger_candidate(
|
||||
&call.func,
|
||||
checker.semantic(),
|
||||
&checker.settings().logger_objects,
|
||||
&checker.settings.logger_objects,
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ pub(crate) fn bad_version_info_comparison(checker: &Checker, test: &Expr, has_el
|
||||
if matches!(op, CmpOp::Lt) {
|
||||
if checker.is_rule_enabled(Rule::BadVersionInfoOrder)
|
||||
// See https://github.com/astral-sh/ruff/issues/15347
|
||||
&& (checker.source_type.is_stub() || is_bad_version_info_in_non_stub_enabled(checker.settings()))
|
||||
&& (checker.source_type.is_stub() || is_bad_version_info_in_non_stub_enabled(checker.settings))
|
||||
{
|
||||
if has_else_clause {
|
||||
checker.report_diagnostic(BadVersionInfoOrder, test.range());
|
||||
|
||||
@@ -173,8 +173,8 @@ pub(crate) fn custom_type_var_instead_of_self(checker: &Checker, binding: &Bindi
|
||||
decorator_list,
|
||||
current_scope,
|
||||
semantic,
|
||||
&checker.settings().pep8_naming.classmethod_decorators,
|
||||
&checker.settings().pep8_naming.staticmethod_decorators,
|
||||
&checker.settings.pep8_naming.classmethod_decorators,
|
||||
&checker.settings.pep8_naming.staticmethod_decorators,
|
||||
);
|
||||
|
||||
let method = match function_kind {
|
||||
|
||||
@@ -75,8 +75,8 @@ pub(crate) fn pep_484_positional_parameter(checker: &Checker, function_def: &ast
|
||||
&function_def.decorator_list,
|
||||
scope,
|
||||
semantic,
|
||||
&checker.settings().pep8_naming.classmethod_decorators,
|
||||
&checker.settings().pep8_naming.staticmethod_decorators,
|
||||
&checker.settings.pep8_naming.classmethod_decorators,
|
||||
&checker.settings.pep8_naming.staticmethod_decorators,
|
||||
);
|
||||
|
||||
// If the method has a `self` or `cls` argument, skip it.
|
||||
|
||||
@@ -708,19 +708,22 @@ fn pytest_fixture_parentheses(
|
||||
fn check_fixture_decorator(checker: &Checker, func_name: &str, decorator: &Decorator) {
|
||||
match &decorator.expression {
|
||||
Expr::Call(ast::ExprCall {
|
||||
func: _,
|
||||
func,
|
||||
arguments,
|
||||
range: _,
|
||||
node_index: _,
|
||||
}) => {
|
||||
if checker.is_rule_enabled(Rule::PytestFixtureIncorrectParenthesesStyle) {
|
||||
if !checker.settings().flake8_pytest_style.fixture_parentheses
|
||||
if !checker.settings.flake8_pytest_style.fixture_parentheses
|
||||
&& arguments.args.is_empty()
|
||||
&& arguments.keywords.is_empty()
|
||||
{
|
||||
let fix = Fix::applicable_edit(
|
||||
Edit::range_deletion(arguments.range()),
|
||||
if checker.comment_ranges().intersects(arguments.range()) {
|
||||
Edit::deletion(func.end(), decorator.end()),
|
||||
if checker
|
||||
.comment_ranges()
|
||||
.intersects(TextRange::new(func.end(), decorator.end()))
|
||||
{
|
||||
Applicability::Unsafe
|
||||
} else {
|
||||
Applicability::Safe
|
||||
@@ -768,7 +771,7 @@ fn check_fixture_decorator(checker: &Checker, func_name: &str, decorator: &Decor
|
||||
}
|
||||
_ => {
|
||||
if checker.is_rule_enabled(Rule::PytestFixtureIncorrectParenthesesStyle) {
|
||||
if checker.settings().flake8_pytest_style.fixture_parentheses {
|
||||
if checker.settings.flake8_pytest_style.fixture_parentheses {
|
||||
let fix = Fix::safe_edit(Edit::insertion(
|
||||
Parentheses::Empty.to_string(),
|
||||
decorator.end(),
|
||||
|
||||
@@ -2,7 +2,7 @@ use ruff_diagnostics::Applicability;
|
||||
use ruff_python_ast::{self as ast, Arguments, Decorator, Expr};
|
||||
|
||||
use ruff_macros::{ViolationMetadata, derive_message_formats};
|
||||
use ruff_text_size::Ranged;
|
||||
use ruff_text_size::{Ranged, TextRange};
|
||||
|
||||
use crate::checkers::ast::Checker;
|
||||
use crate::registry::Rule;
|
||||
@@ -154,18 +154,27 @@ fn pytest_mark_parentheses(
|
||||
fn check_mark_parentheses(checker: &Checker, decorator: &Decorator, marker: &str) {
|
||||
match &decorator.expression {
|
||||
Expr::Call(ast::ExprCall {
|
||||
func: _,
|
||||
arguments,
|
||||
func,
|
||||
arguments:
|
||||
Arguments {
|
||||
args,
|
||||
keywords,
|
||||
range: _,
|
||||
node_index: _,
|
||||
},
|
||||
range: _,
|
||||
node_index: _,
|
||||
}) => {
|
||||
if !checker.settings().flake8_pytest_style.mark_parentheses
|
||||
&& arguments.args.is_empty()
|
||||
&& arguments.keywords.is_empty()
|
||||
if !checker.settings.flake8_pytest_style.mark_parentheses
|
||||
&& args.is_empty()
|
||||
&& keywords.is_empty()
|
||||
{
|
||||
let fix = Fix::applicable_edit(
|
||||
Edit::range_deletion(arguments.range()),
|
||||
if checker.comment_ranges().intersects(arguments.range()) {
|
||||
Edit::deletion(func.end(), decorator.end()),
|
||||
if checker
|
||||
.comment_ranges()
|
||||
.intersects(TextRange::new(func.end(), decorator.end()))
|
||||
{
|
||||
Applicability::Unsafe
|
||||
} else {
|
||||
Applicability::Safe
|
||||
@@ -182,7 +191,7 @@ fn check_mark_parentheses(checker: &Checker, decorator: &Decorator, marker: &str
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
if checker.settings().flake8_pytest_style.mark_parentheses {
|
||||
if checker.settings.flake8_pytest_style.mark_parentheses {
|
||||
let fix = Fix::safe_edit(Edit::insertion(
|
||||
Parentheses::Empty.to_string(),
|
||||
decorator.end(),
|
||||
|
||||
@@ -335,10 +335,7 @@ fn get_parametrize_name_range(
|
||||
|
||||
/// PT006
|
||||
fn check_names(checker: &Checker, call: &ExprCall, expr: &Expr, argvalues: &Expr) {
|
||||
let names_type = checker
|
||||
.settings()
|
||||
.flake8_pytest_style
|
||||
.parametrize_names_type;
|
||||
let names_type = checker.settings.flake8_pytest_style.parametrize_names_type;
|
||||
|
||||
match expr {
|
||||
Expr::StringLiteral(ast::ExprStringLiteral { value, .. }) => {
|
||||
@@ -519,13 +516,10 @@ fn check_names(checker: &Checker, call: &ExprCall, expr: &Expr, argvalues: &Expr
|
||||
|
||||
/// PT007
|
||||
fn check_values(checker: &Checker, names: &Expr, values: &Expr) {
|
||||
let values_type = checker
|
||||
.settings()
|
||||
.flake8_pytest_style
|
||||
.parametrize_values_type;
|
||||
let values_type = checker.settings.flake8_pytest_style.parametrize_values_type;
|
||||
|
||||
let values_row_type = checker
|
||||
.settings()
|
||||
.settings
|
||||
.flake8_pytest_style
|
||||
.parametrize_values_row_type;
|
||||
|
||||
|
||||
@@ -244,13 +244,13 @@ fn exception_needs_match(checker: &Checker, exception: &Expr) {
|
||||
.and_then(|qualified_name| {
|
||||
let qualified_name = qualified_name.to_string();
|
||||
checker
|
||||
.settings()
|
||||
.settings
|
||||
.flake8_pytest_style
|
||||
.raises_require_match_for
|
||||
.iter()
|
||||
.chain(
|
||||
&checker
|
||||
.settings()
|
||||
.settings
|
||||
.flake8_pytest_style
|
||||
.raises_extend_require_match_for,
|
||||
)
|
||||
|
||||
@@ -233,13 +233,13 @@ fn warning_needs_match(checker: &Checker, warning: &Expr) {
|
||||
.and_then(|qualified_name| {
|
||||
let qualified_name = qualified_name.to_string();
|
||||
checker
|
||||
.settings()
|
||||
.settings
|
||||
.flake8_pytest_style
|
||||
.warns_require_match_for
|
||||
.iter()
|
||||
.chain(
|
||||
&checker
|
||||
.settings()
|
||||
.settings
|
||||
.flake8_pytest_style
|
||||
.warns_extend_require_match_for,
|
||||
)
|
||||
|
||||
@@ -149,42 +149,3 @@ PT001.py:81:1: PT001 [*] Use `@pytest.fixture` over `@pytest.fixture()`
|
||||
84 |-)
|
||||
81 |+@pytest.fixture
|
||||
85 82 | def my_fixture(): ...
|
||||
86 83 |
|
||||
87 84 |
|
||||
|
||||
PT001.py:88:1: PT001 [*] Use `@pytest.fixture` over `@pytest.fixture()`
|
||||
|
|
||||
88 | @(pytest.fixture())
|
||||
| ^^^^^^^^^^^^^^^^^^^ PT001
|
||||
89 | def outer_paren_fixture_no_params():
|
||||
90 | return 42
|
||||
|
|
||||
= help: Remove parentheses
|
||||
|
||||
ℹ Safe fix
|
||||
85 85 | def my_fixture(): ...
|
||||
86 86 |
|
||||
87 87 |
|
||||
88 |-@(pytest.fixture())
|
||||
88 |+@(pytest.fixture)
|
||||
89 89 | def outer_paren_fixture_no_params():
|
||||
90 90 | return 42
|
||||
91 91 |
|
||||
|
||||
PT001.py:93:1: PT001 [*] Use `@pytest.fixture` over `@pytest.fixture()`
|
||||
|
|
||||
93 | @(fixture())
|
||||
| ^^^^^^^^^^^^ PT001
|
||||
94 | def outer_paren_imported_fixture_no_params():
|
||||
95 | return 42
|
||||
|
|
||||
= help: Remove parentheses
|
||||
|
||||
ℹ Safe fix
|
||||
90 90 | return 42
|
||||
91 91 |
|
||||
92 92 |
|
||||
93 |-@(fixture())
|
||||
93 |+@(fixture)
|
||||
94 94 | def outer_paren_imported_fixture_no_params():
|
||||
95 95 | return 42
|
||||
|
||||
@@ -130,43 +130,3 @@ PT023.py:82:1: PT023 [*] Use `@pytest.mark.parametrize` over `@pytest.mark.param
|
||||
89 |-)
|
||||
82 |+@pytest.mark.parametrize
|
||||
90 83 | def test_bar(param1, param2): ...
|
||||
91 84 |
|
||||
92 85 |
|
||||
|
||||
PT023.py:93:1: PT023 [*] Use `@pytest.mark.foo` over `@pytest.mark.foo()`
|
||||
|
|
||||
93 | @(pytest.mark.foo())
|
||||
| ^^^^^^^^^^^^^^^^^^^^ PT023
|
||||
94 | def test_outer_paren_mark_function():
|
||||
95 | pass
|
||||
|
|
||||
= help: Remove parentheses
|
||||
|
||||
ℹ Safe fix
|
||||
90 90 | def test_bar(param1, param2): ...
|
||||
91 91 |
|
||||
92 92 |
|
||||
93 |-@(pytest.mark.foo())
|
||||
93 |+@(pytest.mark.foo)
|
||||
94 94 | def test_outer_paren_mark_function():
|
||||
95 95 | pass
|
||||
96 96 |
|
||||
|
||||
PT023.py:99:5: PT023 [*] Use `@pytest.mark.foo` over `@pytest.mark.foo()`
|
||||
|
|
||||
98 | class TestClass:
|
||||
99 | @(pytest.mark.foo())
|
||||
| ^^^^^^^^^^^^^^^^^^^^ PT023
|
||||
100 | def test_method_outer_paren():
|
||||
101 | pass
|
||||
|
|
||||
= help: Remove parentheses
|
||||
|
||||
ℹ Safe fix
|
||||
96 96 |
|
||||
97 97 |
|
||||
98 98 | class TestClass:
|
||||
99 |- @(pytest.mark.foo())
|
||||
99 |+ @(pytest.mark.foo)
|
||||
100 100 | def test_method_outer_paren():
|
||||
101 101 | pass
|
||||
|
||||
@@ -86,7 +86,7 @@ impl<'a, 'b> AvoidableEscapedQuoteChecker<'a, 'b> {
|
||||
fn new(checker: &'a Checker<'b>, target_version: PythonVersion) -> Self {
|
||||
Self {
|
||||
checker,
|
||||
quotes_settings: &checker.settings().flake8_quotes,
|
||||
quotes_settings: &checker.settings.flake8_quotes,
|
||||
supports_pep701: target_version.supports_pep_701(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,7 +251,7 @@ fn text_ends_at_quote(locator: &Locator, range: TextRange, quote: Quote) -> bool
|
||||
|
||||
/// Q002
|
||||
fn docstring(checker: &Checker, range: TextRange) {
|
||||
let quotes_settings = &checker.settings().flake8_quotes;
|
||||
let quotes_settings = &checker.settings.flake8_quotes;
|
||||
let locator = checker.locator();
|
||||
|
||||
let text = locator.slice(range);
|
||||
@@ -302,7 +302,7 @@ fn docstring(checker: &Checker, range: TextRange) {
|
||||
|
||||
/// Q000, Q001
|
||||
fn strings(checker: &Checker, sequence: &[TextRange]) {
|
||||
let quotes_settings = &checker.settings().flake8_quotes;
|
||||
let quotes_settings = &checker.settings.flake8_quotes;
|
||||
let locator = checker.locator();
|
||||
|
||||
let trivia = sequence
|
||||
|
||||
@@ -379,7 +379,7 @@ fn unnecessary_return_none(checker: &Checker, decorator_list: &[Decorator], stac
|
||||
// Skip property functions
|
||||
if is_property(
|
||||
decorator_list,
|
||||
checker.settings().pydocstyle.property_decorators(),
|
||||
checker.settings.pydocstyle.property_decorators(),
|
||||
checker.semantic(),
|
||||
) {
|
||||
return;
|
||||
|
||||
@@ -85,7 +85,7 @@ pub(crate) fn private_member_access(checker: &Checker, expr: &Expr) {
|
||||
}
|
||||
|
||||
if checker
|
||||
.settings()
|
||||
.settings
|
||||
.flake8_self
|
||||
.ignore_names
|
||||
.contains(attr.id())
|
||||
|
||||
@@ -191,11 +191,11 @@ pub(crate) fn multiple_with_statements(
|
||||
content,
|
||||
with_stmt.into(),
|
||||
checker.locator(),
|
||||
checker.settings().pycodestyle.max_line_length,
|
||||
checker.settings().tab_size,
|
||||
checker.settings.pycodestyle.max_line_length,
|
||||
checker.settings.tab_size,
|
||||
)
|
||||
}) {
|
||||
if is_multiple_with_statements_fix_safe_enabled(checker.settings()) {
|
||||
if is_multiple_with_statements_fix_safe_enabled(checker.settings) {
|
||||
Ok(Some(Fix::safe_edit(edit)))
|
||||
} else {
|
||||
Ok(Some(Fix::unsafe_edit(edit)))
|
||||
|
||||
@@ -125,8 +125,8 @@ pub(crate) fn nested_if_statements(
|
||||
content,
|
||||
(&nested_if).into(),
|
||||
checker.locator(),
|
||||
checker.settings().pycodestyle.max_line_length,
|
||||
checker.settings().tab_size,
|
||||
checker.settings.pycodestyle.max_line_length,
|
||||
checker.settings.tab_size,
|
||||
)
|
||||
}) {
|
||||
Ok(Some(Fix::unsafe_edit(edit)))
|
||||
|
||||
@@ -215,8 +215,8 @@ pub(crate) fn if_else_block_instead_of_dict_get(checker: &Checker, stmt_if: &ast
|
||||
&contents,
|
||||
stmt_if.into(),
|
||||
checker.locator(),
|
||||
checker.settings().pycodestyle.max_line_length,
|
||||
checker.settings().tab_size,
|
||||
checker.settings.pycodestyle.max_line_length,
|
||||
checker.settings.tab_size,
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -225,8 +225,8 @@ pub(crate) fn if_else_block_instead_of_if_exp(checker: &Checker, stmt_if: &ast::
|
||||
&contents,
|
||||
stmt_if.into(),
|
||||
checker.locator(),
|
||||
checker.settings().pycodestyle.max_line_length,
|
||||
checker.settings().tab_size,
|
||||
checker.settings.pycodestyle.max_line_length,
|
||||
checker.settings.tab_size,
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -105,8 +105,8 @@ pub(crate) fn convert_for_loop_to_any_all(checker: &Checker, stmt: &Stmt) {
|
||||
&contents,
|
||||
stmt.into(),
|
||||
checker.locator(),
|
||||
checker.settings().pycodestyle.max_line_length,
|
||||
checker.settings().tab_size,
|
||||
checker.settings.pycodestyle.max_line_length,
|
||||
checker.settings.tab_size,
|
||||
) {
|
||||
return;
|
||||
}
|
||||
@@ -195,14 +195,14 @@ pub(crate) fn convert_for_loop_to_any_all(checker: &Checker, stmt: &Stmt) {
|
||||
|
||||
// Don't flag if the resulting expression would exceed the maximum line length.
|
||||
let line_start = checker.locator().line_start(stmt.start());
|
||||
if LineWidthBuilder::new(checker.settings().tab_size)
|
||||
if LineWidthBuilder::new(checker.settings.tab_size)
|
||||
.add_str(
|
||||
checker
|
||||
.locator()
|
||||
.slice(TextRange::new(line_start, stmt.start())),
|
||||
)
|
||||
.add_str(&contents)
|
||||
> checker.settings().pycodestyle.max_line_length
|
||||
> checker.settings.pycodestyle.max_line_length
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -102,11 +102,8 @@ pub(crate) fn suppressible_exception(
|
||||
return;
|
||||
}
|
||||
|
||||
let [
|
||||
ExceptHandler::ExceptHandler(ast::ExceptHandlerExceptHandler {
|
||||
body, range, type_, ..
|
||||
}),
|
||||
] = handlers
|
||||
let [ExceptHandler::ExceptHandler(ast::ExceptHandlerExceptHandler { body, range, .. })] =
|
||||
handlers
|
||||
else {
|
||||
return;
|
||||
};
|
||||
@@ -124,13 +121,7 @@ pub(crate) fn suppressible_exception(
|
||||
};
|
||||
|
||||
let exception = if handler_names.is_empty() {
|
||||
if type_.is_none() {
|
||||
// case where there are no handler names provided at all
|
||||
"BaseException".to_string()
|
||||
} else {
|
||||
// case where handler names is an empty tuple
|
||||
String::new()
|
||||
}
|
||||
"Exception".to_string()
|
||||
} else {
|
||||
handler_names.join(", ")
|
||||
};
|
||||
@@ -151,29 +142,15 @@ pub(crate) fn suppressible_exception(
|
||||
stmt.start(),
|
||||
checker.semantic(),
|
||||
)?;
|
||||
let mut rest: Vec<Edit> = Vec::new();
|
||||
let content: String;
|
||||
if exception == "BaseException" && handler_names.is_empty() {
|
||||
let (import_exception, binding_exception) =
|
||||
checker.importer().get_or_import_symbol(
|
||||
&ImportRequest::import("builtins", &exception),
|
||||
stmt.start(),
|
||||
checker.semantic(),
|
||||
)?;
|
||||
content = format!("with {binding}({binding_exception})");
|
||||
rest.push(import_exception);
|
||||
} else {
|
||||
content = format!("with {binding}({exception})");
|
||||
}
|
||||
rest.push(Edit::range_deletion(
|
||||
checker.locator().full_lines_range(*range),
|
||||
));
|
||||
rest.push(Edit::range_replacement(
|
||||
content,
|
||||
let replace_try = Edit::range_replacement(
|
||||
format!("with {binding}({exception})"),
|
||||
TextRange::at(stmt.start(), "try".text_len()),
|
||||
));
|
||||
|
||||
Ok(Fix::unsafe_edits(import_edit, rest))
|
||||
);
|
||||
let remove_handler = Edit::range_deletion(checker.locator().full_lines_range(*range));
|
||||
Ok(Fix::unsafe_edits(
|
||||
import_edit,
|
||||
[replace_try, remove_handler],
|
||||
))
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ use ruff_python_ast::{self as ast, Arguments, Expr};
|
||||
use ruff_python_semantic::analyze::typing::is_dict;
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
use crate::fix::edits;
|
||||
use crate::{AlwaysFixableViolation, Edit, Fix};
|
||||
use crate::{checkers::ast::Checker, fix::snippet::SourceCodeSnippet};
|
||||
|
||||
@@ -102,11 +101,7 @@ pub(crate) fn zip_dict_keys_and_values(checker: &Checker, expr: &ast::ExprCall)
|
||||
return;
|
||||
}
|
||||
|
||||
let expected = edits::pad(
|
||||
format!("{}.items()", checker.locator().slice(var1)),
|
||||
expr.range(),
|
||||
checker.locator(),
|
||||
);
|
||||
let expected = format!("{}.items()", checker.locator().slice(var1));
|
||||
let actual = checker.locator().slice(expr);
|
||||
|
||||
let mut diagnostic = checker.report_diagnostic(
|
||||
|
||||
@@ -90,7 +90,7 @@ SIM105_0.py:19:1: SIM105 [*] Use `contextlib.suppress(ValueError, OSError)` inst
|
||||
24 23 | # SIM105
|
||||
25 24 | try:
|
||||
|
||||
SIM105_0.py:25:1: SIM105 [*] Use `contextlib.suppress(BaseException)` instead of `try`-`except`-`pass`
|
||||
SIM105_0.py:25:1: SIM105 [*] Use `contextlib.suppress(Exception)` instead of `try`-`except`-`pass`
|
||||
|
|
||||
24 | # SIM105
|
||||
25 | / try:
|
||||
@@ -101,26 +101,25 @@ SIM105_0.py:25:1: SIM105 [*] Use `contextlib.suppress(BaseException)` instead of
|
||||
29 |
|
||||
30 | # SIM105
|
||||
|
|
||||
= help: Replace with `contextlib.suppress(BaseException)`
|
||||
= help: Replace with `contextlib.suppress(Exception)`
|
||||
|
||||
ℹ Unsafe fix
|
||||
1 |+import contextlib
|
||||
2 |+import builtins
|
||||
1 3 | def foo():
|
||||
2 4 | pass
|
||||
3 5 |
|
||||
1 2 | def foo():
|
||||
2 3 | pass
|
||||
3 4 |
|
||||
--------------------------------------------------------------------------------
|
||||
22 24 | pass
|
||||
23 25 |
|
||||
24 26 | # SIM105
|
||||
22 23 | pass
|
||||
23 24 |
|
||||
24 25 | # SIM105
|
||||
25 |-try:
|
||||
27 |+with contextlib.suppress(builtins.BaseException):
|
||||
26 28 | foo()
|
||||
26 |+with contextlib.suppress(Exception):
|
||||
26 27 | foo()
|
||||
27 |-except:
|
||||
28 |- pass
|
||||
29 29 |
|
||||
30 30 | # SIM105
|
||||
31 31 | try:
|
||||
29 28 |
|
||||
30 29 | # SIM105
|
||||
31 30 | try:
|
||||
|
||||
SIM105_0.py:31:1: SIM105 [*] Use `contextlib.suppress(a.Error, b.Error)` instead of `try`-`except`-`pass`
|
||||
|
|
||||
@@ -286,59 +285,3 @@ SIM105_0.py:126:5: SIM105 [*] Use `contextlib.suppress(OSError)` instead of `try
|
||||
127 |+ with contextlib.suppress(OSError): os.makedirs(model_dir);
|
||||
129 128 | \
|
||||
130 129 | #
|
||||
131 130 |
|
||||
|
||||
SIM105_0.py:133:1: SIM105 [*] Use `contextlib.suppress()` instead of `try`-`except`-`pass`
|
||||
|
|
||||
132 | # Regression tests for: https://github.com/astral-sh/ruff/issues/18209
|
||||
133 | / try:
|
||||
134 | | 1 / 0
|
||||
135 | | except ():
|
||||
136 | | pass
|
||||
| |________^ SIM105
|
||||
|
|
||||
= help: Replace with `contextlib.suppress()`
|
||||
|
||||
ℹ Unsafe fix
|
||||
1 |+import contextlib
|
||||
1 2 | def foo():
|
||||
2 3 | pass
|
||||
3 4 |
|
||||
--------------------------------------------------------------------------------
|
||||
130 131 | #
|
||||
131 132 |
|
||||
132 133 | # Regression tests for: https://github.com/astral-sh/ruff/issues/18209
|
||||
133 |-try:
|
||||
134 |+with contextlib.suppress():
|
||||
134 135 | 1 / 0
|
||||
135 |-except ():
|
||||
136 |- pass
|
||||
137 136 |
|
||||
138 137 |
|
||||
139 138 | BaseException = ValueError
|
||||
|
||||
SIM105_0.py:140:1: SIM105 [*] Use `contextlib.suppress(BaseException)` instead of `try`-`except`-`pass`
|
||||
|
|
||||
139 | BaseException = ValueError
|
||||
140 | / try:
|
||||
141 | | int("a")
|
||||
142 | | except BaseException:
|
||||
143 | | pass
|
||||
| |________^ SIM105
|
||||
|
|
||||
= help: Replace with `contextlib.suppress(BaseException)`
|
||||
|
||||
ℹ Unsafe fix
|
||||
1 |+import contextlib
|
||||
1 2 | def foo():
|
||||
2 3 | pass
|
||||
3 4 |
|
||||
--------------------------------------------------------------------------------
|
||||
137 138 |
|
||||
138 139 |
|
||||
139 140 | BaseException = ValueError
|
||||
140 |-try:
|
||||
141 |+with contextlib.suppress(BaseException):
|
||||
141 142 | int("a")
|
||||
142 |-except BaseException:
|
||||
143 |- pass
|
||||
|
||||
@@ -75,21 +75,3 @@ SIM911.py:30:27: SIM911 [*] Use `dict.items()` instead of `zip(dict.keys(), dict
|
||||
30 |- for country, stars in zip(dict.keys(), dict.values()):
|
||||
30 |+ for country, stars in dict.items():
|
||||
31 31 | ...
|
||||
32 32 |
|
||||
33 33 |
|
||||
|
||||
SIM911.py:36:22: SIM911 [*] Use ` flag_stars.items()` instead of `(zip)(flag_stars.keys(), flag_stars.values())`
|
||||
|
|
||||
34 | # https://github.com/astral-sh/ruff/issues/18776
|
||||
35 | flag_stars = {}
|
||||
36 | for country, stars in(zip)(flag_stars.keys(), flag_stars.values()):...
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM911
|
||||
|
|
||||
= help: Replace `(zip)(flag_stars.keys(), flag_stars.values())` with ` flag_stars.items()`
|
||||
|
||||
ℹ Safe fix
|
||||
33 33 |
|
||||
34 34 | # https://github.com/astral-sh/ruff/issues/18776
|
||||
35 35 | flag_stars = {}
|
||||
36 |-for country, stars in(zip)(flag_stars.keys(), flag_stars.values()):...
|
||||
36 |+for country, stars in flag_stars.items():...
|
||||
|
||||
@@ -40,7 +40,7 @@ impl Violation for BannedApi {
|
||||
|
||||
/// TID251
|
||||
pub(crate) fn banned_api<T: Ranged>(checker: &Checker, policy: &NameMatchPolicy, node: &T) {
|
||||
let banned_api = &checker.settings().flake8_tidy_imports.banned_api;
|
||||
let banned_api = &checker.settings.flake8_tidy_imports.banned_api;
|
||||
if let Some(banned_module) = policy.find(banned_api.keys().map(AsRef::as_ref)) {
|
||||
if let Some(reason) = banned_api.get(&banned_module) {
|
||||
checker.report_diagnostic(
|
||||
@@ -56,7 +56,7 @@ pub(crate) fn banned_api<T: Ranged>(checker: &Checker, policy: &NameMatchPolicy,
|
||||
|
||||
/// TID251
|
||||
pub(crate) fn banned_attribute_access(checker: &Checker, expr: &Expr) {
|
||||
let banned_api = &checker.settings().flake8_tidy_imports.banned_api;
|
||||
let banned_api = &checker.settings.flake8_tidy_imports.banned_api;
|
||||
if banned_api.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ pub(crate) fn banned_module_level_imports(checker: &Checker, stmt: &Stmt) {
|
||||
for (policy, node) in &BannedModuleImportPolicies::new(stmt, checker) {
|
||||
if let Some(banned_module) = policy.find(
|
||||
checker
|
||||
.settings()
|
||||
.settings
|
||||
.flake8_tidy_imports
|
||||
.banned_module_level_imports(),
|
||||
) {
|
||||
|
||||
@@ -164,7 +164,7 @@ pub(crate) fn runtime_import_in_type_checking_block(checker: &Checker, scope: &S
|
||||
// since some people will consistently use their
|
||||
// type aliases at runtimes, while others won't, so
|
||||
// the best solution is unclear.
|
||||
if checker.settings().flake8_type_checking.quote_annotations
|
||||
if checker.settings.flake8_type_checking.quote_annotations
|
||||
&& binding.references().all(|reference_id| {
|
||||
let reference = checker.semantic().reference(reference_id);
|
||||
reference.in_typing_context() || reference.in_runtime_evaluated_annotation()
|
||||
|
||||
@@ -273,7 +273,7 @@ pub(crate) fn typing_only_runtime_import(
|
||||
|
||||
// If we're in un-strict mode, don't flag typing-only imports that are
|
||||
// implicitly loaded by way of a valid runtime import.
|
||||
if !checker.settings().flake8_type_checking.strict
|
||||
if !checker.settings.flake8_type_checking.strict
|
||||
&& runtime_imports
|
||||
.iter()
|
||||
.any(|import| is_implicit_import(binding, import))
|
||||
@@ -294,7 +294,7 @@ pub(crate) fn typing_only_runtime_import(
|
||||
.references()
|
||||
.map(|reference_id| checker.semantic().reference(reference_id))
|
||||
.all(|reference| {
|
||||
is_typing_reference(reference, &checker.settings().flake8_type_checking)
|
||||
is_typing_reference(reference, &checker.settings.flake8_type_checking)
|
||||
})
|
||||
{
|
||||
let qualified_name = import.qualified_name();
|
||||
@@ -302,7 +302,7 @@ pub(crate) fn typing_only_runtime_import(
|
||||
if is_exempt(
|
||||
&qualified_name.to_string(),
|
||||
&checker
|
||||
.settings()
|
||||
.settings
|
||||
.flake8_type_checking
|
||||
.exempt_modules
|
||||
.iter()
|
||||
@@ -316,7 +316,7 @@ pub(crate) fn typing_only_runtime_import(
|
||||
|
||||
// Categorize the import, using coarse-grained categorization.
|
||||
let match_source_strategy =
|
||||
if is_full_path_match_source_strategy_enabled(checker.settings()) {
|
||||
if is_full_path_match_source_strategy_enabled(checker.settings) {
|
||||
MatchSourceStrategy::FullPath
|
||||
} else {
|
||||
MatchSourceStrategy::Root
|
||||
@@ -325,14 +325,14 @@ pub(crate) fn typing_only_runtime_import(
|
||||
let import_type = match categorize(
|
||||
&source_name,
|
||||
qualified_name.is_unresolved_import(),
|
||||
&checker.settings().src,
|
||||
&checker.settings.src,
|
||||
checker.package(),
|
||||
checker.settings().isort.detect_same_package,
|
||||
&checker.settings().isort.known_modules,
|
||||
checker.settings.isort.detect_same_package,
|
||||
&checker.settings.isort.known_modules,
|
||||
checker.target_version(),
|
||||
checker.settings().isort.no_sections,
|
||||
&checker.settings().isort.section_order,
|
||||
&checker.settings().isort.default_section,
|
||||
checker.settings.isort.no_sections,
|
||||
&checker.settings.isort.section_order,
|
||||
&checker.settings.isort.default_section,
|
||||
match_source_strategy,
|
||||
) {
|
||||
ImportSection::Known(ImportType::LocalFolder | ImportType::FirstParty) => {
|
||||
|
||||
@@ -250,7 +250,7 @@ impl Argumentable {
|
||||
/// Check a plain function for unused arguments.
|
||||
fn function(argumentable: Argumentable, parameters: &Parameters, scope: &Scope, checker: &Checker) {
|
||||
let ignore_variadic_names = checker
|
||||
.settings()
|
||||
.settings
|
||||
.flake8_unused_arguments
|
||||
.ignore_variadic_names;
|
||||
let args = parameters
|
||||
@@ -276,7 +276,7 @@ fn function(argumentable: Argumentable, parameters: &Parameters, scope: &Scope,
|
||||
/// Check a method for unused arguments.
|
||||
fn method(argumentable: Argumentable, parameters: &Parameters, scope: &Scope, checker: &Checker) {
|
||||
let ignore_variadic_names = checker
|
||||
.settings()
|
||||
.settings
|
||||
.flake8_unused_arguments
|
||||
.ignore_variadic_names;
|
||||
let args = parameters
|
||||
@@ -307,7 +307,7 @@ fn call<'a>(
|
||||
checker: &Checker,
|
||||
) {
|
||||
let semantic = checker.semantic();
|
||||
let dummy_variable_rgx = &checker.settings().dummy_variable_rgx;
|
||||
let dummy_variable_rgx = &checker.settings.dummy_variable_rgx;
|
||||
for arg in parameters {
|
||||
let Some(binding) = scope
|
||||
.get(arg.name())
|
||||
@@ -408,8 +408,8 @@ pub(crate) fn unused_arguments(checker: &Checker, scope: &Scope) {
|
||||
decorator_list,
|
||||
parent,
|
||||
checker.semantic(),
|
||||
&checker.settings().pep8_naming.classmethod_decorators,
|
||||
&checker.settings().pep8_naming.staticmethod_decorators,
|
||||
&checker.settings.pep8_naming.classmethod_decorators,
|
||||
&checker.settings.pep8_naming.staticmethod_decorators,
|
||||
) {
|
||||
function_type::FunctionType::Function => {
|
||||
if checker.is_rule_enabled(Argumentable::Function.rule_code())
|
||||
|
||||
@@ -33,10 +33,6 @@ use crate::{AlwaysFixableViolation, Applicability, Edit, Fix};
|
||||
/// _ = Path()
|
||||
/// ```
|
||||
///
|
||||
/// ## Fix safety
|
||||
/// This fix is marked unsafe if there are comments inside the parentheses, as applying
|
||||
/// the fix will delete them.
|
||||
///
|
||||
/// ## References
|
||||
/// - [Python documentation: `Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path)
|
||||
#[derive(ViolationMetadata)]
|
||||
|
||||
@@ -68,7 +68,7 @@ pub(crate) fn camelcase_imported_as_acronym(
|
||||
&& str::is_cased_uppercase(asname)
|
||||
&& helpers::is_acronym(name, asname)
|
||||
{
|
||||
let ignore_names = &checker.settings().pep8_naming.ignore_names;
|
||||
let ignore_names = &checker.settings.pep8_naming.ignore_names;
|
||||
|
||||
// Ignore any explicitly-allowed names.
|
||||
if ignore_names.matches(name) || ignore_names.matches(asname) {
|
||||
@@ -114,7 +114,7 @@ fn is_ignored_because_of_import_convention(
|
||||
|
||||
// Ignore names that follow a community-agreed import convention.
|
||||
checker
|
||||
.settings()
|
||||
.settings
|
||||
.flake8_import_conventions
|
||||
.aliases
|
||||
.get(&*full_name)
|
||||
|
||||
@@ -81,7 +81,7 @@ pub(crate) fn invalid_argument_name_lambda(checker: &Checker, lambda: &ExprLambd
|
||||
|
||||
/// N803
|
||||
fn invalid_argument_name(checker: &Checker, parameters: &Parameters) {
|
||||
let ignore_names = &checker.settings().pep8_naming.ignore_names;
|
||||
let ignore_names = &checker.settings.pep8_naming.ignore_names;
|
||||
|
||||
for parameter in parameters {
|
||||
let name = parameter.name().as_str();
|
||||
|
||||
@@ -226,8 +226,8 @@ pub(crate) fn invalid_first_argument_name(checker: &Checker, scope: &Scope) {
|
||||
decorator_list,
|
||||
parent_scope,
|
||||
semantic,
|
||||
&checker.settings().pep8_naming.classmethod_decorators,
|
||||
&checker.settings().pep8_naming.staticmethod_decorators,
|
||||
&checker.settings.pep8_naming.classmethod_decorators,
|
||||
&checker.settings.pep8_naming.staticmethod_decorators,
|
||||
) {
|
||||
function_type::FunctionType::Function | function_type::FunctionType::StaticMethod => {
|
||||
return;
|
||||
@@ -260,7 +260,7 @@ pub(crate) fn invalid_first_argument_name(checker: &Checker, scope: &Scope) {
|
||||
|
||||
if &self_or_cls.name == function_type.valid_first_argument_name()
|
||||
|| checker
|
||||
.settings()
|
||||
.settings
|
||||
.pep8_naming
|
||||
.ignore_names
|
||||
.matches(&self_or_cls.name)
|
||||
|
||||
@@ -72,7 +72,7 @@ pub(crate) fn mixed_case_variable_in_class_scope(
|
||||
return;
|
||||
}
|
||||
|
||||
if checker.settings().pep8_naming.ignore_names.matches(name) {
|
||||
if checker.settings.pep8_naming.ignore_names.matches(name) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ pub(crate) fn mixed_case_variable_in_global_scope(checker: &Checker, expr: &Expr
|
||||
return;
|
||||
}
|
||||
|
||||
if checker.settings().pep8_naming.ignore_names.matches(name) {
|
||||
if checker.settings.pep8_naming.ignore_names.matches(name) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ pub(crate) fn non_lowercase_variable_in_function(checker: &Checker, expr: &Expr,
|
||||
}
|
||||
|
||||
// Ignore explicitly-allowed names.
|
||||
if checker.settings().pep8_naming.ignore_names.matches(name) {
|
||||
if checker.settings.pep8_naming.ignore_names.matches(name) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -235,7 +235,7 @@ pub(crate) fn manual_dict_comprehension(checker: &Checker, for_stmt: &ast::StmtF
|
||||
return;
|
||||
}
|
||||
|
||||
if is_fix_manual_dict_comprehension_enabled(checker.settings()) {
|
||||
if is_fix_manual_dict_comprehension_enabled(checker.settings) {
|
||||
let binding_stmt = binding.statement(checker.semantic());
|
||||
let binding_value = binding_stmt.and_then(|binding_stmt| match binding_stmt {
|
||||
ast::Stmt::AnnAssign(assign) => assign.value.as_deref(),
|
||||
|
||||
@@ -337,7 +337,7 @@ pub(crate) fn manual_list_comprehension(checker: &Checker, for_stmt: &ast::StmtF
|
||||
);
|
||||
|
||||
// TODO: once this fix is stabilized, change the rule to always fixable
|
||||
if is_fix_manual_list_comprehension_enabled(checker.settings()) {
|
||||
if is_fix_manual_list_comprehension_enabled(checker.settings) {
|
||||
diagnostic.try_set_fix(|| {
|
||||
convert_to_list_extend(
|
||||
comprehension_type,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use ruff_diagnostics::Applicability;
|
||||
use ruff_macros::{ViolationMetadata, derive_message_formats};
|
||||
use ruff_python_ast::statement_visitor::{StatementVisitor, walk_stmt};
|
||||
use ruff_python_ast::{self as ast, Arguments, Expr, Stmt};
|
||||
@@ -6,7 +5,6 @@ use ruff_python_semantic::analyze::typing::find_assigned_value;
|
||||
use ruff_text_size::TextRange;
|
||||
|
||||
use crate::checkers::ast::Checker;
|
||||
use crate::fix::edits;
|
||||
use crate::{AlwaysFixableViolation, Edit, Fix};
|
||||
|
||||
/// ## What it does
|
||||
@@ -37,19 +35,6 @@ use crate::{AlwaysFixableViolation, Edit, Fix};
|
||||
/// for i in items:
|
||||
/// print(i)
|
||||
/// ```
|
||||
///
|
||||
/// ## Fix safety
|
||||
/// This rule's fix is marked as unsafe if there's comments in the
|
||||
/// `list()` call, as comments may be removed.
|
||||
///
|
||||
/// For example, the fix would be marked as unsafe in the following case:
|
||||
/// ```python
|
||||
/// items = (1, 2, 3)
|
||||
/// for i in list( # comment
|
||||
/// items
|
||||
/// ):
|
||||
/// print(i)
|
||||
/// ```
|
||||
#[derive(ViolationMetadata)]
|
||||
pub(crate) struct UnnecessaryListCast;
|
||||
|
||||
@@ -104,7 +89,7 @@ pub(crate) fn unnecessary_list_cast(checker: &Checker, iter: &Expr, body: &[Stmt
|
||||
..
|
||||
}) => {
|
||||
let mut diagnostic = checker.report_diagnostic(UnnecessaryListCast, *list_range);
|
||||
diagnostic.set_fix(remove_cast(checker, *list_range, *iterable_range));
|
||||
diagnostic.set_fix(remove_cast(*list_range, *iterable_range));
|
||||
}
|
||||
Expr::Name(ast::ExprName {
|
||||
id,
|
||||
@@ -131,7 +116,7 @@ pub(crate) fn unnecessary_list_cast(checker: &Checker, iter: &Expr, body: &[Stmt
|
||||
}
|
||||
|
||||
let mut diagnostic = checker.report_diagnostic(UnnecessaryListCast, *list_range);
|
||||
diagnostic.set_fix(remove_cast(checker, *list_range, *iterable_range));
|
||||
diagnostic.set_fix(remove_cast(*list_range, *iterable_range));
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
@@ -139,19 +124,10 @@ pub(crate) fn unnecessary_list_cast(checker: &Checker, iter: &Expr, body: &[Stmt
|
||||
}
|
||||
|
||||
/// Generate a [`Fix`] to remove a `list` cast from an expression.
|
||||
fn remove_cast(checker: &Checker, list_range: TextRange, iterable_range: TextRange) -> Fix {
|
||||
let content = edits::pad(
|
||||
checker.locator().slice(iterable_range).to_string(),
|
||||
list_range,
|
||||
checker.locator(),
|
||||
);
|
||||
Fix::applicable_edit(
|
||||
Edit::range_replacement(content, list_range),
|
||||
if checker.comment_ranges().intersects(list_range) {
|
||||
Applicability::Unsafe
|
||||
} else {
|
||||
Applicability::Safe
|
||||
},
|
||||
fn remove_cast(list_range: TextRange, iterable_range: TextRange) -> Fix {
|
||||
Fix::safe_edits(
|
||||
Edit::deletion(list_range.start(), iterable_range.start()),
|
||||
[Edit::deletion(iterable_range.end(), list_range.end())],
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -168,7 +168,7 @@ PERF101.py:34:10: PERF101 [*] Do not cast an iterable to `list` before iterating
|
||||
|
|
||||
= help: Remove `list()` cast
|
||||
|
||||
ℹ Unsafe fix
|
||||
ℹ Safe fix
|
||||
31 31 | ):
|
||||
32 32 | pass
|
||||
33 33 |
|
||||
@@ -238,56 +238,3 @@ PERF101.py:86:10: PERF101 [*] Do not cast an iterable to `list` before iterating
|
||||
86 |-for i in builtins.list(nested_tuple): # PERF101
|
||||
86 |+for i in nested_tuple: # PERF101
|
||||
87 87 | pass
|
||||
88 88 |
|
||||
89 89 | # https://github.com/astral-sh/ruff/issues/18783
|
||||
|
||||
PERF101.py:91:9: PERF101 [*] Do not cast an iterable to `list` before iterating over it
|
||||
|
|
||||
89 | # https://github.com/astral-sh/ruff/issues/18783
|
||||
90 | items = (1, 2, 3)
|
||||
91 | for i in(list)(items):
|
||||
| ^^^^^^^^^^^^^ PERF101
|
||||
92 | print(i)
|
||||
|
|
||||
= help: Remove `list()` cast
|
||||
|
||||
ℹ Safe fix
|
||||
88 88 |
|
||||
89 89 | # https://github.com/astral-sh/ruff/issues/18783
|
||||
90 90 | items = (1, 2, 3)
|
||||
91 |-for i in(list)(items):
|
||||
91 |+for i in items:
|
||||
92 92 | print(i)
|
||||
93 93 |
|
||||
94 94 | # https://github.com/astral-sh/ruff/issues/18784
|
||||
|
||||
PERF101.py:96:10: PERF101 [*] Do not cast an iterable to `list` before iterating over it
|
||||
|
|
||||
94 | # https://github.com/astral-sh/ruff/issues/18784
|
||||
95 | items = (1, 2, 3)
|
||||
96 | for i in ( # 1
|
||||
| __________^
|
||||
97 | | list # 2
|
||||
98 | | # 3
|
||||
99 | | )( # 4
|
||||
100 | | items # 5
|
||||
101 | | # 6
|
||||
102 | | ):
|
||||
| |_^ PERF101
|
||||
103 | print(i)
|
||||
|
|
||||
= help: Remove `list()` cast
|
||||
|
||||
ℹ Unsafe fix
|
||||
93 93 |
|
||||
94 94 | # https://github.com/astral-sh/ruff/issues/18784
|
||||
95 95 | items = (1, 2, 3)
|
||||
96 |-for i in ( # 1
|
||||
97 |- list # 2
|
||||
98 |- # 3
|
||||
99 |-)( # 4
|
||||
100 |- items # 5
|
||||
101 |- # 6
|
||||
102 |-):
|
||||
96 |+for i in items:
|
||||
103 97 | print(i)
|
||||
|
||||
@@ -887,7 +887,7 @@ pub(crate) fn check_docstring(
|
||||
return;
|
||||
};
|
||||
|
||||
if checker.settings().pydoclint.ignore_one_line_docstrings && is_one_line(docstring) {
|
||||
if checker.settings.pydoclint.ignore_one_line_docstrings && is_one_line(docstring) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -919,7 +919,7 @@ pub(crate) fn check_docstring(
|
||||
if should_document_returns(function_def)
|
||||
&& !returns_documented(docstring, &docstring_sections, convention)
|
||||
{
|
||||
let extra_property_decorators = checker.settings().pydocstyle.property_decorators();
|
||||
let extra_property_decorators = checker.settings.pydocstyle.property_decorators();
|
||||
if !definition.is_property(extra_property_decorators, semantic) {
|
||||
if !body_entries.returns.is_empty() {
|
||||
match function_def.returns.as_deref() {
|
||||
|
||||
@@ -1789,7 +1789,7 @@ fn missing_args(checker: &Checker, docstring: &Docstring, docstrings_args: &FxHa
|
||||
|
||||
// Check specifically for `vararg` and `kwarg`, which can be prefixed with a
|
||||
// single or double star, respectively.
|
||||
if !checker.settings().pydocstyle.ignore_var_parameters() {
|
||||
if !checker.settings.pydocstyle.ignore_var_parameters() {
|
||||
if let Some(arg) = function.parameters.vararg.as_ref() {
|
||||
let arg_name = arg.name.as_str();
|
||||
let starred_arg_name = format!("*{arg_name}");
|
||||
|
||||
@@ -39,7 +39,7 @@ pub(crate) fn unused_annotation(checker: &Checker, scope: &Scope) {
|
||||
let binding = checker.semantic().binding(binding_id);
|
||||
if binding.kind.is_annotation()
|
||||
&& binding.is_unused()
|
||||
&& !checker.settings().dummy_variable_rgx.is_match(name)
|
||||
&& !checker.settings.dummy_variable_rgx.is_match(name)
|
||||
{
|
||||
Some((name.to_string(), binding.range()))
|
||||
} else {
|
||||
|
||||
@@ -231,7 +231,7 @@ enum UnusedImportContext {
|
||||
|
||||
fn is_first_party(import: &AnyImport, checker: &Checker) -> bool {
|
||||
let source_name = import.source_name().join(".");
|
||||
let match_source_strategy = if is_full_path_match_source_strategy_enabled(checker.settings()) {
|
||||
let match_source_strategy = if is_full_path_match_source_strategy_enabled(checker.settings) {
|
||||
MatchSourceStrategy::FullPath
|
||||
} else {
|
||||
MatchSourceStrategy::Root
|
||||
@@ -239,14 +239,14 @@ fn is_first_party(import: &AnyImport, checker: &Checker) -> bool {
|
||||
let category = isort::categorize(
|
||||
&source_name,
|
||||
import.qualified_name().is_unresolved_import(),
|
||||
&checker.settings().src,
|
||||
&checker.settings.src,
|
||||
checker.package(),
|
||||
checker.settings().isort.detect_same_package,
|
||||
&checker.settings().isort.known_modules,
|
||||
checker.settings.isort.detect_same_package,
|
||||
&checker.settings.isort.known_modules,
|
||||
checker.target_version(),
|
||||
checker.settings().isort.no_sections,
|
||||
&checker.settings().isort.section_order,
|
||||
&checker.settings().isort.default_section,
|
||||
checker.settings.isort.no_sections,
|
||||
&checker.settings.isort.section_order,
|
||||
&checker.settings.isort.default_section,
|
||||
match_source_strategy,
|
||||
);
|
||||
matches! {
|
||||
@@ -317,7 +317,7 @@ pub(crate) fn unused_import(checker: &Checker, scope: &Scope) {
|
||||
// If an import is marked as required, avoid treating it as unused, regardless of whether
|
||||
// it was _actually_ used.
|
||||
if checker
|
||||
.settings()
|
||||
.settings
|
||||
.isort
|
||||
.required_imports
|
||||
.iter()
|
||||
@@ -328,7 +328,7 @@ pub(crate) fn unused_import(checker: &Checker, scope: &Scope) {
|
||||
|
||||
// If an import was marked as allowed, avoid treating it as unused.
|
||||
if checker
|
||||
.settings()
|
||||
.settings
|
||||
.pyflakes
|
||||
.allowed_unused_imports
|
||||
.iter()
|
||||
@@ -366,8 +366,8 @@ pub(crate) fn unused_import(checker: &Checker, scope: &Scope) {
|
||||
}
|
||||
|
||||
let in_init = checker.path().ends_with("__init__.py");
|
||||
let fix_init = !checker.settings().ignore_init_module_imports;
|
||||
let preview_mode = is_dunder_init_fix_unused_import_enabled(checker.settings());
|
||||
let fix_init = !checker.settings.ignore_init_module_imports;
|
||||
let preview_mode = is_dunder_init_fix_unused_import_enabled(checker.settings);
|
||||
let dunder_all_exprs = find_dunder_all_exprs(checker.semantic());
|
||||
|
||||
// Generate a diagnostic for every import, but share fixes across all imports within the same
|
||||
|
||||
@@ -187,7 +187,7 @@ fn remove_unused_variable(binding: &Binding, checker: &Checker) -> Option<Fix> {
|
||||
} else {
|
||||
let name = binding.name(checker.source());
|
||||
let renamed = format!("_{name}");
|
||||
if checker.settings().dummy_variable_rgx.is_match(&renamed) {
|
||||
if checker.settings.dummy_variable_rgx.is_match(&renamed) {
|
||||
let edit = Edit::range_replacement(renamed, binding.range());
|
||||
|
||||
return Some(Fix::unsafe_edit(edit).isolate(isolation));
|
||||
|
||||
@@ -69,7 +69,7 @@ pub(crate) fn bad_dunder_method_name(checker: &Checker, method: &ast::StmtFuncti
|
||||
// If the name is explicitly allowed, skip it.
|
||||
if is_known_dunder_method(&method.name)
|
||||
|| checker
|
||||
.settings()
|
||||
.settings
|
||||
.pylint
|
||||
.allow_dunder_method_names
|
||||
.contains(method.name.as_str())
|
||||
|
||||
@@ -71,8 +71,8 @@ pub(crate) fn bad_staticmethod_argument(checker: &Checker, scope: &Scope) {
|
||||
decorator_list,
|
||||
parent,
|
||||
checker.semantic(),
|
||||
&checker.settings().pep8_naming.classmethod_decorators,
|
||||
&checker.settings().pep8_naming.staticmethod_decorators,
|
||||
&checker.settings.pep8_naming.classmethod_decorators,
|
||||
&checker.settings.pep8_naming.staticmethod_decorators,
|
||||
);
|
||||
|
||||
match type_ {
|
||||
|
||||
@@ -91,7 +91,7 @@ fn is_banned_module_level_import(policy: &NameMatchPolicy, checker: &Checker) ->
|
||||
policy
|
||||
.find(
|
||||
checker
|
||||
.settings()
|
||||
.settings
|
||||
.flake8_tidy_imports
|
||||
.banned_module_level_imports(),
|
||||
)
|
||||
|
||||
@@ -193,15 +193,6 @@ pub(crate) fn invalid_string_characters(context: &LintContext, token: &Token, lo
|
||||
let location = token.start() + TextSize::try_from(column).unwrap();
|
||||
let c = match_.chars().next().unwrap();
|
||||
let range = TextRange::at(location, c.text_len());
|
||||
|
||||
let is_escaped = &text[..column]
|
||||
.chars()
|
||||
.rev()
|
||||
.take_while(|c| *c == '\\')
|
||||
.count()
|
||||
% 2
|
||||
== 1;
|
||||
|
||||
let (replacement, diagnostic) = match c {
|
||||
'\x08' => (
|
||||
"\\b",
|
||||
@@ -232,7 +223,7 @@ pub(crate) fn invalid_string_characters(context: &LintContext, token: &Token, lo
|
||||
continue;
|
||||
};
|
||||
|
||||
if !token.unwrap_string_flags().is_raw_string() && !is_escaped {
|
||||
if !token.unwrap_string_flags().is_raw_string() {
|
||||
let edit = Edit::range_replacement(replacement.to_string(), range);
|
||||
diagnostic.set_fix(Fix::safe_edit(edit));
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ pub(crate) fn logging_call(checker: &Checker, call: &ast::ExprCall) {
|
||||
if !logging::is_logger_candidate(
|
||||
&call.func,
|
||||
checker.semantic(),
|
||||
&checker.settings().logger_objects,
|
||||
&checker.settings.logger_objects,
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ pub(crate) fn magic_value_comparison(checker: &Checker, left: &Expr, comparators
|
||||
|
||||
for comparison_expr in std::iter::once(left).chain(comparators) {
|
||||
if let Some(value) = as_literal(comparison_expr) {
|
||||
if is_magic_value(value, &checker.settings().pylint.allow_magic_value_types) {
|
||||
if is_magic_value(value, &checker.settings.pylint.allow_magic_value_types) {
|
||||
checker.report_diagnostic(
|
||||
MagicValueComparison {
|
||||
value: checker.locator().slice(comparison_expr).to_string(),
|
||||
|
||||
@@ -60,7 +60,7 @@ pub(crate) fn misplaced_bare_raise(checker: &Checker, raise: &ast::StmtRaise) {
|
||||
return;
|
||||
}
|
||||
|
||||
if in_dunder_method("__exit__", checker.semantic(), checker.settings()) {
|
||||
if in_dunder_method("__exit__", checker.semantic(), checker.settings) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user