Skip to content

Commit

Permalink
Address deprecated ruff ANN101 (#4238)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Jun 26, 2024
1 parent d5173cb commit b89e7c3
Show file tree
Hide file tree
Showing 45 changed files with 308 additions and 293 deletions.
5 changes: 1 addition & 4 deletions .config/pydoclint-baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ src/molecule/api.py
DOC107: Method `UserListMap.__getitem__`: The option `--arg-type-hints-in-signature` is `True` but not all args in the signature have type hints
DOC103: Method `UserListMap.__getitem__`: Docstring arguments are different from function arguments. (Or could be other formatting issues: https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the docstring: [i: ].
DOC201: Method `UserListMap.__getitem__` does not have a return section in docstring
DOC101: Function `drivers`: Docstring contains fewer arguments than in function signature.
DOC106: Function `drivers`: The option `--arg-type-hints-in-signature` is `True` but there are no argument type hints in the signature
DOC107: Function `drivers`: The option `--arg-type-hints-in-signature` is `True` but not all args in the signature have type hints
DOC103: Function `drivers`: Docstring arguments are different from function arguments. (Or could be other formatting issues: https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the docstring: [config: ].
DOC201: Function `drivers` does not have a return section in docstring
DOC203: Function `drivers` return type(s) in docstring not consistent with the return annotation. Return annotation has 1 type(s); docstring return section has 0 type(s).
DOC101: Function `verifiers`: Docstring contains fewer arguments than in function signature.
Expand Down Expand Up @@ -237,6 +233,7 @@ src/molecule/config.py
DOC101: Method `Config.__init__`: Docstring contains fewer arguments than in function signature.
DOC107: Method `Config.__init__`: The option `--arg-type-hints-in-signature` is `True` but not all args in the signature have type hints
DOC103: Method `Config.__init__`: Docstring arguments are different from function arguments. (Or could be other formatting issues: https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the docstring: [ansible_args: , args: , command_args: , molecule_file: str].
DOC201: Method `Config.driver` does not have a return section in docstring
DOC203: Method `Config._get_config` return type(s) in docstring not consistent with the return annotation. Return annotation types: ['MutableMapping']; docstring return section types: ['dict']
DOC203: Method `Config._reget_config` return type(s) in docstring not consistent with the return annotation. Return annotation has 0 type(s); docstring return section has 1 type(s).
DOC101: Method `Config._combine`: Docstring contains fewer arguments than in function signature.
Expand Down
3 changes: 3 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ repos:
rev: 0.5.1
hooks:
- id: pydoclint
# This allows automatic reduction of the baseline file when needed.
entry: sh -ec "pydoclint . && pydoclint --generate-baseline=1 ."
pass_filenames: false

- repo: https://github.com/pycqa/pylint.git
rev: v3.2.3
Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ module = [
[tool.pydoclint]
arg-type-hints-in-docstring = false
baseline = ".config/pydoclint-baseline.txt"
exclude = '\.git|\.tox|build|out|venv'
show-filenames-in-every-violation-message = true
skip-checking-short-docstrings = false
style = "google"
Expand Down Expand Up @@ -345,11 +346,17 @@ verbosity_assertions = 2
[tool.ruff]
builtins = ["__"]
cache-dir = "./.cache/.ruff"
external = [
"DOC" # pydoclint
]
fix = true
line-length = 100
target-version = "py310"

[tool.ruff.lint]
extend-ignore = [
"ANN101" # missing-type-self (deprecated)
]
select = ["ALL"]

[tool.ruff.lint.flake8-pytest-style]
Expand Down
15 changes: 10 additions & 5 deletions src/molecule/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import traceback

from collections import UserList
from typing import Any

import pluggy

Expand All @@ -25,16 +26,16 @@ class UserListMap(UserList): # type: ignore[type-arg]
foo.boo
"""

def __getitem__(self, i): # type: ignore[no-untyped-def] # noqa: ANN001, ANN101, ANN204
def __getitem__(self, i): # type: ignore[no-untyped-def] # noqa: ANN001, ANN204
"""Implement indexing."""
if isinstance(i, int):
return super().__getitem__(i)
return self.__dict__[i]

def get(self, key, default): # type: ignore[no-untyped-def] # noqa: ANN001, ANN101, ANN201, D102
def get(self, key, default): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, D102
return self.__dict__.get(key, default)

def append(self, item) -> None: # type: ignore[no-untyped-def] # noqa: ANN001, ANN101, D102
def append(self, item) -> None: # type: ignore[no-untyped-def] # noqa: ANN001, D102
self.__dict__[str(item)] = item
super().append(item)

Expand All @@ -48,8 +49,12 @@ class IncompatibleMoleculeRuntimeWarning(MoleculeRuntimeWarning):


@cache
def drivers(config=None) -> UserListMap: # type: ignore[no-untyped-def] # noqa: ANN001
"""Return list of active drivers."""
def drivers(config: Any | None = None) -> UserListMap: # noqa: ANN401
"""Return list of active drivers.
Args:
config: plugin config
"""
plugins = UserListMap()
pm = pluggy.PluginManager("molecule.driver")
try:
Expand Down
2 changes: 1 addition & 1 deletion src/molecule/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class App:
"""App class that keep runtime status."""

def __init__(self) -> None: # noqa: ANN101
def __init__(self) -> None:
"""Create a new app instance."""
self.runtime = Runtime(isolated=False)

Expand Down
6 changes: 3 additions & 3 deletions src/molecule/command/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
class Base(metaclass=abc.ABCMeta):
"""An abstract base class used to define the command interface."""

def __init__(self, c: config.Config) -> None: # noqa: ANN101
def __init__(self, c: config.Config) -> None:
"""Initialize code for all command classes.
Args:
Expand All @@ -70,7 +70,7 @@ def __init__(self, c: config.Config) -> None: # noqa: ANN101
self._config = c
self._setup()

def __init_subclass__(cls) -> None: # noqa: ANN101
def __init_subclass__(cls) -> None:
"""Decorate execute from all subclasses."""
super().__init_subclass__()
for wrapper in logger.get_section_loggers():
Expand All @@ -87,7 +87,7 @@ def execute(
action_args: An optional list of arguments to pass to the action.
"""

def _setup(self) -> None: # noqa: ANN101
def _setup(self) -> None:
"""Prepare Molecule's provisioner and returns None."""
self._config.write()
self._config.provisioner.write_config()
Expand Down
2 changes: 1 addition & 1 deletion src/molecule/command/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
class Check(base.Base):
"""Check Command Class."""

def execute(self, action_args=None): # type: ignore[no-untyped-def] # noqa: ANN001, ANN101, ANN201, ARG002
def execute(self, action_args=None): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, ARG002
"""Execute the actions necessary to perform a `molecule check` and returns None."""
self._config.provisioner.check()

Expand Down
2 changes: 1 addition & 1 deletion src/molecule/command/cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
class Cleanup(base.Base):
"""Cleanup Command Class."""

def execute(self, action_args=None): # type: ignore[no-untyped-def] # noqa: ANN001, ANN101, ANN201, ARG002
def execute(self, action_args=None): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, ARG002
"""Execute the actions necessary to cleanup the instances and returns None."""
if not self._config.provisioner.playbooks.cleanup:
msg = "Skipping, cleanup playbook not configured."
Expand Down
2 changes: 1 addition & 1 deletion src/molecule/command/converge.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
class Converge(base.Base):
"""Converge Command Class."""

def execute(self, action_args: list[str] | None = None) -> None: # noqa: ANN101, ARG002
def execute(self, action_args: list[str] | None = None) -> None: # noqa: ARG002
"""Execute the actions necessary to perform a `molecule converge` and returns None."""
self._config.provisioner.converge()
self._config.state.change_state("converged", True) # noqa: FBT003
Expand Down
2 changes: 1 addition & 1 deletion src/molecule/command/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
class Create(base.Base):
"""Create Command Class."""

def execute(self, action_args=None): # type: ignore[no-untyped-def] # noqa: ANN001, ANN101, ANN201, ARG002
def execute(self, action_args=None): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, ARG002
"""Execute the actions necessary to perform a `molecule create` and returns None."""
self._config.state.change_state("driver", self._config.driver.name)

Expand Down
2 changes: 1 addition & 1 deletion src/molecule/command/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
class Dependency(base.Base):
"""Dependency Command Class."""

def execute(self, action_args=None): # type: ignore[no-untyped-def] # noqa: ANN001, ANN101, ANN201, ARG002
def execute(self, action_args=None): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, ARG002
"""Execute the actions necessary to perform a `molecule dependency` and returns None."""
self._config.dependency.execute()

Expand Down
2 changes: 1 addition & 1 deletion src/molecule/command/destroy.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
class Destroy(base.Base):
"""Destroy Command Class."""

def execute(self, action_args=None): # type: ignore[no-untyped-def] # noqa: ANN001, ANN101, ANN201, ARG002
def execute(self, action_args=None): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, ARG002
"""Execute the actions necessary to perform a `molecule destroy` and returns None."""
if self._config.command_args.get("destroy") == "never":
msg = "Skipping, '--destroy=never' requested."
Expand Down
6 changes: 3 additions & 3 deletions src/molecule/command/idempotence.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Idempotence(base.Base):
the scenario will be considered idempotent.
"""

def execute(self, action_args=None): # type: ignore[no-untyped-def] # noqa: ANN001, ANN101, ANN201, ARG002
def execute(self, action_args=None): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, ARG002
"""Execute the actions necessary to perform a `molecule idempotence` and returns None."""
if not self._config.state.converged:
msg = "Instances not converged. Please converge instances first."
Expand All @@ -56,7 +56,7 @@ def execute(self, action_args=None): # type: ignore[no-untyped-def] # noqa: AN
msg = f"Idempotence test failed because of the following tasks:\n{details}"
util.sysexit_with_message(msg)

def _is_idempotent(self, output): # type: ignore[no-untyped-def] # noqa: ANN001, ANN101, ANN202
def _is_idempotent(self, output): # type: ignore[no-untyped-def] # noqa: ANN001, ANN202
"""Parse the output of the provisioning for changed and returns a bool.
Args:
Expand All @@ -77,7 +77,7 @@ def _is_idempotent(self, output): # type: ignore[no-untyped-def] # noqa: ANN00

return True

def _non_idempotent_tasks(self, output): # type: ignore[no-untyped-def] # noqa: ANN001, ANN101, ANN202
def _non_idempotent_tasks(self, output): # type: ignore[no-untyped-def] # noqa: ANN001, ANN202
"""Parse the output to identify the non idempotent tasks.
Args:
Expand Down
2 changes: 1 addition & 1 deletion src/molecule/command/init/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Base:

__metaclass__ = abc.ABCMeta

def _validate_template_dir(self, template_dir): # type: ignore[no-untyped-def] # noqa: ANN001, ANN101, ANN202
def _validate_template_dir(self, template_dir): # type: ignore[no-untyped-def] # noqa: ANN001, ANN202
if not os.path.isdir(template_dir): # noqa: PTH112
util.sysexit_with_message(
"The specified template directory (" + str(template_dir) + ") does not exist",
Expand Down
4 changes: 2 additions & 2 deletions src/molecule/command/init/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ class Scenario(base.Base):
Initialize a new scenario using a embedded template.
"""

def __init__(self, command_args: dict[str, str]) -> None: # noqa: ANN101
def __init__(self, command_args: dict[str, str]) -> None:
"""Construct Scenario."""
self._command_args = command_args

def execute(self, action_args=None): # type: ignore[no-untyped-def] # noqa: ANN001, ANN101, ANN201, ARG002
def execute(self, action_args=None): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, ARG002
"""Execute the actions necessary to perform a `molecule init scenario` and returns None."""
scenario_name = self._command_args["scenario_name"]

Expand Down
2 changes: 1 addition & 1 deletion src/molecule/command/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
class List(base.Base):
"""List command shows information about current scenarios."""

def execute(self, action_args=None): # type: ignore[no-untyped-def] # noqa: ANN001, ANN101, ANN201, ARG002
def execute(self, action_args=None): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, ARG002
"""Execute the actions necessary to perform a `molecule list` and returns None."""
return self._config.driver.status()

Expand Down
8 changes: 4 additions & 4 deletions src/molecule/command/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@
class Login(base.Base):
"""Login Command Class."""

def __init__(self, c) -> None: # type: ignore[no-untyped-def] # noqa: ANN001, ANN101
def __init__(self, c) -> None: # type: ignore[no-untyped-def] # noqa: ANN001
"""Construct Login."""
super().__init__(c)
self._pt = None

def execute(self, action_args=None): # type: ignore[no-untyped-def] # noqa: ANN001, ANN101, ANN201, ARG002
def execute(self, action_args=None): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, ARG002
"""Execute the actions necessary to perform a `molecule login` and returns None."""
c = self._config
if (not c.state.created) and c.driver.managed:
Expand All @@ -52,7 +52,7 @@ def execute(self, action_args=None): # type: ignore[no-untyped-def] # noqa: AN
hostname = self._get_hostname(hosts) # type: ignore[no-untyped-call]
self._get_login(hostname) # type: ignore[no-untyped-call]

def _get_hostname(self, hosts): # type: ignore[no-untyped-def] # noqa: ANN001, ANN101, ANN202
def _get_hostname(self, hosts): # type: ignore[no-untyped-def] # noqa: ANN001, ANN202
hostname = self._config.command_args.get("host")
host_list = "\n".join(sorted(hosts))
if hostname is None:
Expand Down Expand Up @@ -87,7 +87,7 @@ def _get_hostname(self, hosts): # type: ignore[no-untyped-def] # noqa: ANN001,

return match[0]

def _get_login(self, hostname): # type: ignore[no-untyped-def] # pragma: no cover # noqa: ANN001, ANN101, ANN202
def _get_login(self, hostname): # type: ignore[no-untyped-def] # pragma: no cover # noqa: ANN001, ANN202
# ruff: noqa: S605,S607
lines, columns = os.popen("stty size", "r").read().split()
login_options = self._config.driver.login_options(hostname)
Expand Down
2 changes: 1 addition & 1 deletion src/molecule/command/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class Prepare(base.Base):
molecule.yml.
"""

def execute(self, action_args=None): # type: ignore[no-untyped-def] # noqa: ANN001, ANN101, ANN201, ARG002
def execute(self, action_args=None): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, ARG002
"""Execute the actions necessary to prepare the instances and returns None."""
if self._config.state.prepared and not self._config.command_args.get("force"):
msg = "Skipping, instances already prepared."
Expand Down
2 changes: 1 addition & 1 deletion src/molecule/command/side_effect.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class SideEffect(base.Base):
See the provisioners documentation for further details.
"""

def execute(self, action_args=None): # type: ignore[no-untyped-def] # noqa: ANN001, ANN101, ANN201
def execute(self, action_args=None): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201
"""Execute the actions necessary to perform a `molecule side-effect` and returns None."""
if not self._config.provisioner.playbooks.side_effect:
msg = "Skipping, side effect playbook not configured."
Expand Down
2 changes: 1 addition & 1 deletion src/molecule/command/syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
class Syntax(base.Base):
"""Syntax Command Class."""

def execute(self, action_args=None): # type: ignore[no-untyped-def] # noqa: ANN001, ANN101, ANN201, ARG002
def execute(self, action_args=None): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, ARG002
"""Execute the actions necessary to perform a `molecule syntax` and returns None."""
self._config.provisioner.syntax()

Expand Down
2 changes: 1 addition & 1 deletion src/molecule/command/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
class Test(base.Base):
"""Test Command Class."""

def execute(self, action_args=None): # type: ignore[no-untyped-def] # noqa: ANN001, ANN101, ANN201
def execute(self, action_args=None): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201
"""Execute the actions necessary to perform a `molecule test` and returns None."""


Expand Down
2 changes: 1 addition & 1 deletion src/molecule/command/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
class Verify(base.Base):
"""Verify Command Class."""

def execute(self, action_args=None): # type: ignore[no-untyped-def] # noqa: ANN001, ANN101, ANN201
def execute(self, action_args=None): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201
"""Execute the actions necessary to perform a `molecule verify` and returns None."""
self._config.verifier.execute(action_args)

Expand Down
Loading

0 comments on commit b89e7c3

Please sign in to comment.