Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ruff: Address B #3377

Merged
merged 1 commit into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
warnings.warn(
f"This architecture ({arch}) is not supported by libyaml, performance will be degraded.",
category=RuntimeWarning,
stacklevel=1,
)
else:
pytest.fail(
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ ignore = [
"A",
"ANN",
"ARG002", # Unused method argument (currently in too many places)
"B",
"D",
"FBT",
"PGH",
Expand Down
1 change: 1 addition & 0 deletions src/ansiblelint/_vendor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def _ensure_vendored_path_entry() -> None:
"loaded ({}). This may result in undefined behavior.".format(
", ".join(sorted(already_loaded_vendored_modules)),
),
stacklevel=1,
)


Expand Down
4 changes: 2 additions & 2 deletions src/ansiblelint/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def __call__(
# But if --write comes first, then it might actually be a lintable.
maybe_lintable = Path(values)
if maybe_lintable.exists():
setattr(namespace, "lintables", [values])
namespace.lintables = [values]
values = []
if isinstance(values, str):
values = values.split(",")
Expand Down Expand Up @@ -536,7 +536,7 @@ def merge_config(file_config: dict[Any, Any], cli_config: Options) -> Options:
# append default kinds to the custom list
kinds = file_config.get("kinds", [])
kinds.extend(DEFAULT_KINDS)
setattr(cli_config, "kinds", kinds)
cli_config.kinds = kinds

return cli_config

Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def __init__(
self.abspath = self.path.expanduser().absolute()

if self.kind == "yaml":
self.data # pylint: disable=pointless-statement
_ = self.data # pylint: disable=pointless-statement

def _guess_kind(self) -> None:
if self.kind == "yaml":
Expand Down
4 changes: 1 addition & 3 deletions src/ansiblelint/rules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import sys
from collections import defaultdict
from collections.abc import Iterable, Iterator, MutableMapping, MutableSequence
from functools import lru_cache
from importlib import import_module
from pathlib import Path
from typing import Any, cast
Expand Down Expand Up @@ -57,7 +56,6 @@ def rule_config(self) -> dict[str, Any]:
"""Retrieve rule specific configuration."""
return get_rule_config(self.id)

@lru_cache(maxsize=256)
def get_config(self, key: str) -> Any:
"""Return a configured value for given key string."""
return self.rule_config.get(key, None)
Expand Down Expand Up @@ -353,7 +351,7 @@ def all_subclasses(cls: type) -> set[type]:
# python may load other rule classes, some outside the tested rule
# directories.
if (
getattr(rule, "id")
rule.id # type: ignore[attr-defined]
and Path(inspect.getfile(rule)).parent.absolute()
in [Path(x).absolute() for x in dirs]
and issubclass(rule, BaseRule)
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def matchyaml(self, file: Lintable) -> list[MatchError]:
if str(file.kind) == "vars":
data = parse_yaml_from_file(str(file.path))
# pylint: disable=unused-variable
for key, v, path in nested_items_path(data):
for key, v, _path in nested_items_path(data):
if isinstance(v, AnsibleUnicode):
reformatted, details, tag = self.check_whitespace(
v,
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/yaml_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _fetch_skips(data: Any, collector: dict[int, set[str]]) -> dict[int, set[str
collector[data.get(LINE_NUMBER_KEY)].update(rules)
if isinstance(data, Iterable) and not isinstance(data, str):
if isinstance(data, dict):
for entry, value in data.items():
for _entry, value in data.items():
_fetch_skips(value, collector)
else: # must be some kind of list
for entry in data:
Expand Down
6 changes: 3 additions & 3 deletions src/ansiblelint/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ def normalize_task_v2(task: dict[str, Any]) -> dict[str, Any]:
message=exc.message,
filename=task.get(FILENAME_KEY, "Unknown"),
lineno=task.get(LINE_NUMBER_KEY, 0),
)
) from exc

# denormalize shell -> command conversion
if "_uses_shell" in arguments:
Expand Down Expand Up @@ -900,7 +900,7 @@ def compose_node(parent: yaml.nodes.Node, index: int) -> yaml.nodes.Node:
if not isinstance(node, yaml.nodes.Node):
msg = "Unexpected yaml data."
raise RuntimeError(msg)
setattr(node, "__line__", line + 1)
node.__line__ = line + 1 # type: ignore[attr-defined]
return node

def construct_mapping(
Expand Down Expand Up @@ -1019,7 +1019,7 @@ def is_playbook(filename: str) -> bool:

# pylint: disable=too-many-statements
def get_lintables(
opts: Options = Options(),
opts: Options = options,
args: list[str] | None = None,
) -> list[Lintable]:
"""Detect files and directories that are lintable."""
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/yaml_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ def loads(self, stream: str) -> Any:
text, preamble_comment = self._pre_process_yaml(stream)
data = self.load(stream=text)
if preamble_comment is not None:
setattr(data, "preamble_comment", preamble_comment)
data.preamble_comment = preamble_comment
return data

def dumps(self, data: Any) -> str:
Expand Down
2 changes: 1 addition & 1 deletion test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def test_ensure_write_cli_does_not_consume_lintables(
file_config = cli.load_config(config)[0]

file_value = file_config.get("write_list")
orig_cli_value = getattr(options, "write_list")
orig_cli_value = options.write_list
cli_value = cli.WriteArgAction.merge_write_list_config(
from_file=[],
from_cli=orig_cli_value,
Expand Down
2 changes: 1 addition & 1 deletion test/test_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_transformer( # pylint: disable=too-many-arguments, too-many-locals

Based on TestRunner::test_runner
"""
setattr(config_options, "write_list", ["all"])
config_options.write_list = ["all"]
transformer = Transformer(result=runner_result, options=config_options)
transformer.run()

Expand Down