Skip to content

Commit

Permalink
Address pylint protected-access (#2007)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Mar 15, 2022
1 parent 2ca36a0 commit 497d441
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 4 deletions.
1 change: 0 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ disable =
consider-using-f-string,
dangerous-default-value,
duplicate-code,
protected-access,

[TYPECHECK]
# pylint is unable to detect Namespace attributes and will throw a E1101
Expand Down
3 changes: 3 additions & 0 deletions src/ansiblelint/rules/syntax_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def test_get_ansible_syntax_check_matches() -> None:
lintable = Lintable(
"examples/playbooks/conflicting_action.yml", kind="playbook"
)
# pylint: disable=protected-access
result = AnsibleSyntaxCheckRule._get_ansible_syntax_check_matches(lintable)
assert result[0].linenumber == 4
assert result[0].column == 7
Expand All @@ -148,6 +149,7 @@ def test_get_ansible_syntax_check_matches() -> None:
def test_empty_playbook() -> None:
"""Validate detection of empty-playbook."""
lintable = Lintable("examples/playbooks/empty_playbook.yml", kind="playbook")
# pylint: disable=protected-access
result = AnsibleSyntaxCheckRule._get_ansible_syntax_check_matches(lintable)
assert result[0].linenumber == 1
# We internally convert absolute paths returned by ansible into paths
Expand All @@ -165,6 +167,7 @@ def test_extra_vars_passed_to_command(config_options: Any) -> None:
}
lintable = Lintable("examples/playbooks/extra_vars.yml", kind="playbook")

# pylint: disable=protected-access
result = AnsibleSyntaxCheckRule._get_ansible_syntax_check_matches(lintable)

assert not result
1 change: 1 addition & 0 deletions src/ansiblelint/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def run(self) -> List[MatchError]:

# -- phase 1 : syntax check in parallel --
def worker(lintable: Lintable) -> List[MatchError]:
# pylint: disable=protected-access
return AnsibleSyntaxCheckRule._get_ansible_syntax_check_matches(lintable)

# playbooks: List[Lintable] = []
Expand Down
4 changes: 3 additions & 1 deletion src/ansiblelint/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,9 @@ def construct_mapping(
if hasattr(node, "__line__"):
mapping[LINE_NUMBER_KEY] = node.__line__
else:
mapping[LINE_NUMBER_KEY] = mapping._line_number
mapping[
LINE_NUMBER_KEY
] = mapping._line_number # pylint: disable=protected-access
mapping[FILENAME_KEY] = lintable.path
return mapping

Expand Down
1 change: 1 addition & 0 deletions src/ansiblelint/yaml_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ def represent_octal(
v = format(data, "o")
anchor = data.yaml_anchor(any=True)
# noinspection PyProtectedMember
# pylint: disable=protected-access
return representer.insert_underscore("0", v, data._underscore, anchor=anchor)


Expand Down
5 changes: 4 additions & 1 deletion test/test_formatter_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ def test_base_formatter_when_base_dir(
base_formatter = BaseFormatter(base_dir, relative_path) # type: ignore

# When
output_path = base_formatter._format_path(path)
output_path = base_formatter._format_path(path) # pylint: disable=protected-access

# Then
assert isinstance(output_path, str)
# pylint: disable=protected-access
assert base_formatter._base_dir is None or isinstance(base_formatter._base_dir, str)
assert output_path == str(path)

Expand All @@ -49,10 +50,12 @@ def test_base_formatter_when_base_dir_is_given_and_relative_is_true(
base_formatter = BaseFormatter(base_dir, True) # type: ignore

# When
# pylint: disable=protected-access
output_path = base_formatter._format_path(path)

# Then
assert isinstance(output_path, str)
# pylint: disable=protected-access
assert isinstance(base_formatter._base_dir, str)
assert output_path == Path(path).name

Expand Down
2 changes: 1 addition & 1 deletion test/test_yaml_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
def fixture_empty_lintable() -> Lintable:
"""Return a Lintable with no contents."""
lintable = Lintable("__empty_file__")
lintable._content = ""
lintable._content = "" # pylint: disable=protected-access
return lintable


Expand Down

0 comments on commit 497d441

Please sign in to comment.