Skip to content

Commit

Permalink
Address ruff PLW, E501 (#1758)
Browse files Browse the repository at this point in the history
* Address ruff PLW exception

* Address ruff TRY exceptions

* Address E501

* Move some of the non-fixable rules to the top
  • Loading branch information
shatakshiiii authored May 16, 2024
1 parent dea8fd2 commit b47635f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
11 changes: 5 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,11 @@ exclude = ["tests/fixtures/**", ".git"]

[tool.ruff.lint]
ignore = [
'ERA001', # [*] Found commented-out code
'INP001', # File `docs/_ext/regenerate_docs.py` is part of an implicit namespace package. Add an `__init__.py`.
'PLW2901', # `for` loop variable `info_name` overwritten by assignment target
"RET504", # Unnecessary variable assignment before `return` statement
# temporary disabled until we fix them:
'ANN001', # Missing type annotation for function argument `output`
'ANN002', # Missing type annotation for `*args`
'ANN003', # Missing type annotation for `**kwargs`
Expand Down Expand Up @@ -291,14 +296,11 @@ ignore = [
'D101', # Missing docstring in public class
'D102', # Missing docstring in public method
'D103', # Missing docstring in public function
'E501', # line-too-long, already covered by black
'ERA001', # [*] Found commented-out code
'FBT001', # Boolean positional arg in function definition
'FBT002', # Boolean default value in function definition
'FBT003', # Boolean positional value in function call
'FIX001', # Line contains FIXME
'FIX002', # Line contains TODO
'INP001', # File `docs/_ext/regenerate_docs.py` is part of an implicit namespace package. Add an `__init__.py`.
'N802', # Function name `formatTime` should be lowercase
'N806', # Variable `FType` in function should be lowercase
'N812', # Lowercase `__version_collection_doc_cache__` imported as non-lowercase `VERSION_CDC`
Expand All @@ -314,9 +316,7 @@ ignore = [
'PLR0915', # Too many statements (58 > 50)
'PLR2004', # Magic value used in comparison, consider replacing 2 with a constant variable
'PLR5501', # Consider using `elif` instead of `else` then `if` to remove one indentation level
'PLW0120', # `else` clause on loop without a `break` statement; remove the `else` and de-indent all the code inside it
'PLW0603', # Using the global statement to update `DIAGNOSTIC_FAILURES` is discouraged
'PLW2901', # `for` loop variable `info_name` overwritten by assignment target
'PT005', # Fixture `_settings_samples` returns a value, remove leading underscore
'PT019', # Fixture `_mocked_func` without value is injected as parameter, use `@pytest.mark.usefixtures` instead
'PT022', # [*] No teardown in fixture `cmd_in_tty`, use `return` instead of `yield`
Expand All @@ -339,7 +339,6 @@ ignore = [
'PTH123', # `open()` should be replaced by `Path.open()`
'PTH204', # `os.path.getmtime` should be replaced by `Path.stat().st_mtime`
'PTH207', # Replace `glob` with `Path.glob` or `Path.rglob`
'RET504', # Unnecessary variable assignment before `return` statement
'RET505', # Unnecessary `else` after `return` statement
'RUF005', # [*] Consider `[self._name, *shlex.split(self._interaction.action.match.groupdict()["params"] or "")]` instead of concatenation
'RUF012', # Mutable class attributes should be annotated with `typing.ClassVar`
Expand Down
3 changes: 1 addition & 2 deletions src/ansible_navigator/tm_tokenize/fchainmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,4 @@ def __getitem__(self, key: TKey_contra) -> TValue_co:
return mapping[key]
except KeyError:
pass
else:
raise KeyError(key)
raise KeyError(key)
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,8 @@ def pytest_configure(config: pytest.Config) -> None:
config_file == "/etc/ansible/ansible.cfg" and is_config_empty(config_file)
):
pytest.exit(
f"Please remove or empty the ansible config file '{config_file}' before testing, as this will likely break the test results."
f"Please remove or empty the ansible config file '{config_file}' "
"before testing, as this will likely break the test results."
)

# look for ansible-navigator settings file
Expand Down
5 changes: 1 addition & 4 deletions tests/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,14 @@ class BaseScenario:
name: str


_AUTO_ID_COUNTER = 0


def id_func(param: Any) -> str:
"""Generate id for tests.
:param param: the parametrized data
:return: Returns a string.
"""
result = ""
global _AUTO_ID_COUNTER
_AUTO_ID_COUNTER = 0
if isinstance(param, str):
result = param
elif hasattr(param, "value") and isinstance(param.value, str): # covers for Enums too
Expand Down
6 changes: 5 additions & 1 deletion tests/unit/test_catalog_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@


def test_worker_with_failed_get_docstring() -> None:
"""Test worker function when get_docstring fails and get_doc_withast method is used to parse the content."""
"""Test worker function.
Test worker function when get_docstring fails and
get_doc_withast method is used to parse the content.
"""
# Create the queues
pending_queue: multiprocessing.Queue[Any] = multiprocessing.Queue()
completed_queue: multiprocessing.Queue[Any] = multiprocessing.Queue()
Expand Down

0 comments on commit b47635f

Please sign in to comment.