Skip to content

Commit

Permalink
Remove type for self (#326)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Nov 12, 2024
1 parent b0c1d58 commit 52d428f
Show file tree
Hide file tree
Showing 14 changed files with 75 additions and 66 deletions.
18 changes: 11 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ repos:
- prettier-plugin-toml
- prettier-plugin-sort-json

- repo: https://github.com/psf/black
rev: 24.10.0
hooks:
- id: black

- repo: https://github.com/pappasam/toml-sort
rev: v0.23.1
hooks:
Expand All @@ -59,14 +54,23 @@ repos:
- id: tox-ini-fmt

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.2
rev: v0.7.3
hooks:
- id: ruff
args:
- --fix
- --exit-non-zero-on-fix
types_or: [python, pyi]
- id: ruff-format # must be after ruff
types_or: [python, pyi]

- repo: https://github.com/psf/black # must be after ruff
rev: 24.10.0
hooks:
- id: black

- repo: https://github.com/streetsidesoftware/cspell-cli
rev: v8.15.2
rev: v8.16.0
hooks:
- id: cspell
name: Spell check with cspell
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,10 @@ line-length = 100
target-version = "py310"

[tool.ruff.lint]
ignore = [
"COM812", # conflicts with ISC001 on format
"ISC001" # conflicts with COM812 on format
]
select = ["ALL"]

[tool.ruff.lint.flake8-pytest-style]
Expand Down
38 changes: 19 additions & 19 deletions src/ansible_creator/arg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@
class Parser:
"""A parser for the command line arguments."""

def __init__(self: Parser) -> None:
def __init__(self) -> None:
"""Initialize the parser."""
self.args: argparse.Namespace
self.pending_logs: list[Msg] = []

def parse_args(self: Parser) -> tuple[argparse.Namespace, list[Msg]]:
def parse_args(self) -> tuple[argparse.Namespace, list[Msg]]:
"""Parse the root arguments.
Returns:
Expand Down Expand Up @@ -104,7 +104,7 @@ def parse_args(self: Parser) -> tuple[argparse.Namespace, list[Msg]]:

return self.args, self.pending_logs

def _add(self: Parser, subparser: SubParser[ArgumentParser]) -> None:
def _add(self, subparser: SubParser[ArgumentParser]) -> None:
"""Add resources to an existing Ansible project.
Args:
Expand Down Expand Up @@ -217,7 +217,7 @@ def _add_args_plugin_common(self, parser: ArgumentParser) -> None:
"current working directory.",
)

def _add_resource(self: Parser, subparser: SubParser[ArgumentParser]) -> None:
def _add_resource(self, subparser: SubParser[ArgumentParser]) -> None:
"""Add resources to an existing Ansible project.
Args:
Expand All @@ -237,7 +237,7 @@ def _add_resource(self: Parser, subparser: SubParser[ArgumentParser]) -> None:
self._add_resource_devfile(subparser=subparser)
self._add_resource_role(subparser=subparser)

def _add_resource_devcontainer(self: Parser, subparser: SubParser[ArgumentParser]) -> None:
def _add_resource_devcontainer(self, subparser: SubParser[ArgumentParser]) -> None:
"""Add devcontainer files to an existing Ansible project.
Args:
Expand All @@ -259,7 +259,7 @@ def _add_resource_devcontainer(self: Parser, subparser: SubParser[ArgumentParser

self._add_args_common(parser)

def _add_resource_devfile(self: Parser, subparser: SubParser[ArgumentParser]) -> None:
def _add_resource_devfile(self, subparser: SubParser[ArgumentParser]) -> None:
"""Add a devfile file to an existing Ansible project.
Args:
Expand All @@ -281,7 +281,7 @@ def _add_resource_devfile(self: Parser, subparser: SubParser[ArgumentParser]) ->
self._add_overwrite(parser)
self._add_args_common(parser)

def _add_resource_role(self: Parser, subparser: SubParser[ArgumentParser]) -> None:
def _add_resource_role(self, subparser: SubParser[ArgumentParser]) -> None:
"""Add a role to an existing Ansible collection.
Args:
Expand All @@ -305,7 +305,7 @@ def _add_resource_role(self: Parser, subparser: SubParser[ArgumentParser]) -> No
)
self._add_args_common(parser)

def _add_plugin(self: Parser, subparser: SubParser[ArgumentParser]) -> None:
def _add_plugin(self, subparser: SubParser[ArgumentParser]) -> None:
"""Add a plugin to an Ansible project.
Args:
Expand All @@ -326,7 +326,7 @@ def _add_plugin(self: Parser, subparser: SubParser[ArgumentParser]) -> None:
self._add_plugin_filter(subparser=subparser)
self._add_plugin_lookup(subparser=subparser)

def _add_plugin_action(self: Parser, subparser: SubParser[ArgumentParser]) -> None:
def _add_plugin_action(self, subparser: SubParser[ArgumentParser]) -> None:
"""Add an action plugin to an existing Ansible collection project.
Args:
Expand All @@ -340,7 +340,7 @@ def _add_plugin_action(self: Parser, subparser: SubParser[ArgumentParser]) -> No
self._add_args_common(parser)
self._add_args_plugin_common(parser)

def _add_plugin_filter(self: Parser, subparser: SubParser[ArgumentParser]) -> None:
def _add_plugin_filter(self, subparser: SubParser[ArgumentParser]) -> None:
"""Add a filter plugin to an existing Ansible collection project.
Args:
Expand All @@ -354,7 +354,7 @@ def _add_plugin_filter(self: Parser, subparser: SubParser[ArgumentParser]) -> No
self._add_args_common(parser)
self._add_args_plugin_common(parser)

def _add_plugin_lookup(self: Parser, subparser: SubParser[ArgumentParser]) -> None:
def _add_plugin_lookup(self, subparser: SubParser[ArgumentParser]) -> None:
"""Add a lookup plugin to an existing Ansible collection project.
Args:
Expand Down Expand Up @@ -391,7 +391,7 @@ def _add_overwrite(self, parser: ArgumentParser) -> None:
help="Flag that restricts overwriting operation.",
)

def _init(self: Parser, subparser: SubParser[ArgumentParser]) -> None:
def _init(self, subparser: SubParser[ArgumentParser]) -> None:
"""Initialize an Ansible project.
Args:
Expand All @@ -411,7 +411,7 @@ def _init(self: Parser, subparser: SubParser[ArgumentParser]) -> None:
self._init_collection(subparser=subparser)
self._init_playbook(subparser=subparser)

def _init_collection(self: Parser, subparser: SubParser[ArgumentParser]) -> None:
def _init_collection(self, subparser: SubParser[ArgumentParser]) -> None:
"""Initialize an Ansible collection.
Args:
Expand Down Expand Up @@ -440,7 +440,7 @@ def _init_collection(self: Parser, subparser: SubParser[ArgumentParser]) -> None
self._add_args_common(parser)
self._add_args_init_common(parser)

def _init_playbook(self: Parser, subparser: SubParser[ArgumentParser]) -> None:
def _init_playbook(self, subparser: SubParser[ArgumentParser]) -> None:
"""Initialize an Ansible playbook.
Args:
Expand Down Expand Up @@ -498,7 +498,7 @@ def _valid_collection_name(self, collection: str) -> str:
self.pending_logs.append(Msg(prefix=Level.CRITICAL, message=msg))
return collection

def handle_deprecations(self: Parser) -> bool: # noqa: C901
def handle_deprecations(self) -> bool: # noqa: C901
"""Start parsing args passed from Cli.
Returns:
Expand Down Expand Up @@ -560,7 +560,7 @@ class ArgumentParser(argparse.ArgumentParser):
"""A custom argument parser."""

def add_argument( # type: ignore[override]
self: ArgumentParser,
self,
*args: Any, # noqa: ANN401
**kwargs: Any, # noqa: ANN401
) -> None:
Expand All @@ -578,7 +578,7 @@ def add_argument( # type: ignore[override]
super().add_argument(*args, **kwargs)

def add_argument_group(
self: ArgumentParser,
self,
*args: Any, # noqa: ANN401
**kwargs: Any, # noqa: ANN401
) -> argparse._ArgumentGroup:
Expand All @@ -604,7 +604,7 @@ def add_argument_group(
class CustomHelpFormatter(HelpFormatter):
"""A custom help formatter."""

def __init__(self: CustomHelpFormatter, prog: str) -> None:
def __init__(self, prog: str) -> None:
"""Initialize the help formatter.
Args:
Expand All @@ -620,7 +620,7 @@ def __init__(self: CustomHelpFormatter, prog: str) -> None:
)

def _format_action_invocation(
self: CustomHelpFormatter,
self,
action: argparse.Action,
) -> str:
"""Format the action invocation.
Expand Down
10 changes: 5 additions & 5 deletions src/ansible_creator/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
class Cli:
"""Class representing the ansible-creator Cli."""

def __init__(self: Cli) -> None:
def __init__(self) -> None:
"""Initialize the Cli and parse Cli args."""
self.args: dict[str, Any]
self.output: Output
self.pending_logs: list[Msg]
self.term_features: TermFeatures
self.parse_args()

def init_output(self: Cli) -> None:
def init_output(self) -> None:
"""Initialize the output object.
In case the arg parsing exited early, set some sane default values.
Expand All @@ -56,18 +56,18 @@ def init_output(self: Cli) -> None:
display="json" if self.args.pop("json", None) else "text",
)

def parse_args(self: Cli) -> None:
def parse_args(self) -> None:
"""Start parsing args passed from Cli."""
args, pending_logs = Parser().parse_args()
self.args = vars(args)
self.pending_logs = pending_logs

def process_pending_logs(self: Cli) -> None:
def process_pending_logs(self) -> None:
"""Log any pending logs."""
for msg in self.pending_logs:
getattr(self.output, msg.prefix.value.lower())(msg.message)

def run(self: Cli) -> None:
def run(self) -> None:
"""Dispatch work to correct subcommand class."""
self.output.debug(msg=f"parsed args {self.args!s}")
subcommand = self.args["subcommand"]
Expand Down
2 changes: 1 addition & 1 deletion src/ansible_creator/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Config:
type: str = ""
path: str = ""

def __post_init__(self: Config) -> None:
def __post_init__(self) -> None:
"""Post process config values."""
if self.project == "ansible-project":
object.__setattr__(self, "project", "playbook")
Expand Down
6 changes: 3 additions & 3 deletions src/ansible_creator/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class CreatorError(Exception):
"""Class representing exceptions raised from creator code."""

def __init__(self: CreatorError, message: str) -> None:
def __init__(self, message: str) -> None:
"""Instantiate an object of this class.
Args:
Expand All @@ -16,7 +16,7 @@ def __init__(self: CreatorError, message: str) -> None:
self._message = message

@property
def message(self: CreatorError) -> str:
def message(self) -> str:
"""Craft and return the CreatorError message.
Includes the 'cause' when raised from another exception.
Expand All @@ -29,7 +29,7 @@ def message(self: CreatorError) -> str:
msg += f"\n{self.__cause__!s}"
return msg

def __str__(self: CreatorError) -> str:
def __str__(self) -> str:
"""Return a string representation of the exception.
Returns:
Expand Down
Loading

0 comments on commit 52d428f

Please sign in to comment.