Skip to content

Commit 52d428f

Browse files
authored
Remove type for self (#326)
1 parent b0c1d58 commit 52d428f

14 files changed

Lines changed: 75 additions & 66 deletions

File tree

.pre-commit-config.yaml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ repos:
4343
- prettier-plugin-toml
4444
- prettier-plugin-sort-json
4545

46-
- repo: https://github.com/psf/black
47-
rev: 24.10.0
48-
hooks:
49-
- id: black
50-
5146
- repo: https://github.com/pappasam/toml-sort
5247
rev: v0.23.1
5348
hooks:
@@ -59,14 +54,23 @@ repos:
5954
- id: tox-ini-fmt
6055

6156
- repo: https://github.com/astral-sh/ruff-pre-commit
62-
rev: v0.7.2
57+
rev: v0.7.3
6358
hooks:
6459
- id: ruff
6560
args:
61+
- --fix
6662
- --exit-non-zero-on-fix
63+
types_or: [python, pyi]
64+
- id: ruff-format # must be after ruff
65+
types_or: [python, pyi]
66+
67+
- repo: https://github.com/psf/black # must be after ruff
68+
rev: 24.10.0
69+
hooks:
70+
- id: black
6771

6872
- repo: https://github.com/streetsidesoftware/cspell-cli
69-
rev: v8.15.2
73+
rev: v8.16.0
7074
hooks:
7175
- id: cspell
7276
name: Spell check with cspell

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,10 @@ line-length = 100
342342
target-version = "py310"
343343

344344
[tool.ruff.lint]
345+
ignore = [
346+
"COM812", # conflicts with ISC001 on format
347+
"ISC001" # conflicts with COM812 on format
348+
]
345349
select = ["ALL"]
346350

347351
[tool.ruff.lint.flake8-pytest-style]

src/ansible_creator/arg_parser.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@
4646
class Parser:
4747
"""A parser for the command line arguments."""
4848

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

54-
def parse_args(self: Parser) -> tuple[argparse.Namespace, list[Msg]]:
54+
def parse_args(self) -> tuple[argparse.Namespace, list[Msg]]:
5555
"""Parse the root arguments.
5656
5757
Returns:
@@ -104,7 +104,7 @@ def parse_args(self: Parser) -> tuple[argparse.Namespace, list[Msg]]:
104104

105105
return self.args, self.pending_logs
106106

107-
def _add(self: Parser, subparser: SubParser[ArgumentParser]) -> None:
107+
def _add(self, subparser: SubParser[ArgumentParser]) -> None:
108108
"""Add resources to an existing Ansible project.
109109
110110
Args:
@@ -217,7 +217,7 @@ def _add_args_plugin_common(self, parser: ArgumentParser) -> None:
217217
"current working directory.",
218218
)
219219

220-
def _add_resource(self: Parser, subparser: SubParser[ArgumentParser]) -> None:
220+
def _add_resource(self, subparser: SubParser[ArgumentParser]) -> None:
221221
"""Add resources to an existing Ansible project.
222222
223223
Args:
@@ -237,7 +237,7 @@ def _add_resource(self: Parser, subparser: SubParser[ArgumentParser]) -> None:
237237
self._add_resource_devfile(subparser=subparser)
238238
self._add_resource_role(subparser=subparser)
239239

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

260260
self._add_args_common(parser)
261261

262-
def _add_resource_devfile(self: Parser, subparser: SubParser[ArgumentParser]) -> None:
262+
def _add_resource_devfile(self, subparser: SubParser[ArgumentParser]) -> None:
263263
"""Add a devfile file to an existing Ansible project.
264264
265265
Args:
@@ -281,7 +281,7 @@ def _add_resource_devfile(self: Parser, subparser: SubParser[ArgumentParser]) ->
281281
self._add_overwrite(parser)
282282
self._add_args_common(parser)
283283

284-
def _add_resource_role(self: Parser, subparser: SubParser[ArgumentParser]) -> None:
284+
def _add_resource_role(self, subparser: SubParser[ArgumentParser]) -> None:
285285
"""Add a role to an existing Ansible collection.
286286
287287
Args:
@@ -305,7 +305,7 @@ def _add_resource_role(self: Parser, subparser: SubParser[ArgumentParser]) -> No
305305
)
306306
self._add_args_common(parser)
307307

308-
def _add_plugin(self: Parser, subparser: SubParser[ArgumentParser]) -> None:
308+
def _add_plugin(self, subparser: SubParser[ArgumentParser]) -> None:
309309
"""Add a plugin to an Ansible project.
310310
311311
Args:
@@ -326,7 +326,7 @@ def _add_plugin(self: Parser, subparser: SubParser[ArgumentParser]) -> None:
326326
self._add_plugin_filter(subparser=subparser)
327327
self._add_plugin_lookup(subparser=subparser)
328328

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

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

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

394-
def _init(self: Parser, subparser: SubParser[ArgumentParser]) -> None:
394+
def _init(self, subparser: SubParser[ArgumentParser]) -> None:
395395
"""Initialize an Ansible project.
396396
397397
Args:
@@ -411,7 +411,7 @@ def _init(self: Parser, subparser: SubParser[ArgumentParser]) -> None:
411411
self._init_collection(subparser=subparser)
412412
self._init_playbook(subparser=subparser)
413413

414-
def _init_collection(self: Parser, subparser: SubParser[ArgumentParser]) -> None:
414+
def _init_collection(self, subparser: SubParser[ArgumentParser]) -> None:
415415
"""Initialize an Ansible collection.
416416
417417
Args:
@@ -440,7 +440,7 @@ def _init_collection(self: Parser, subparser: SubParser[ArgumentParser]) -> None
440440
self._add_args_common(parser)
441441
self._add_args_init_common(parser)
442442

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

501-
def handle_deprecations(self: Parser) -> bool: # noqa: C901
501+
def handle_deprecations(self) -> bool: # noqa: C901
502502
"""Start parsing args passed from Cli.
503503
504504
Returns:
@@ -560,7 +560,7 @@ class ArgumentParser(argparse.ArgumentParser):
560560
"""A custom argument parser."""
561561

562562
def add_argument( # type: ignore[override]
563-
self: ArgumentParser,
563+
self,
564564
*args: Any, # noqa: ANN401
565565
**kwargs: Any, # noqa: ANN401
566566
) -> None:
@@ -578,7 +578,7 @@ def add_argument( # type: ignore[override]
578578
super().add_argument(*args, **kwargs)
579579

580580
def add_argument_group(
581-
self: ArgumentParser,
581+
self,
582582
*args: Any, # noqa: ANN401
583583
**kwargs: Any, # noqa: ANN401
584584
) -> argparse._ArgumentGroup:
@@ -604,7 +604,7 @@ def add_argument_group(
604604
class CustomHelpFormatter(HelpFormatter):
605605
"""A custom help formatter."""
606606

607-
def __init__(self: CustomHelpFormatter, prog: str) -> None:
607+
def __init__(self, prog: str) -> None:
608608
"""Initialize the help formatter.
609609
610610
Args:
@@ -620,7 +620,7 @@ def __init__(self: CustomHelpFormatter, prog: str) -> None:
620620
)
621621

622622
def _format_action_invocation(
623-
self: CustomHelpFormatter,
623+
self,
624624
action: argparse.Action,
625625
) -> str:
626626
"""Format the action invocation.

src/ansible_creator/cli.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@
2525
class Cli:
2626
"""Class representing the ansible-creator Cli."""
2727

28-
def __init__(self: Cli) -> None:
28+
def __init__(self) -> None:
2929
"""Initialize the Cli and parse Cli args."""
3030
self.args: dict[str, Any]
3131
self.output: Output
3232
self.pending_logs: list[Msg]
3333
self.term_features: TermFeatures
3434
self.parse_args()
3535

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

59-
def parse_args(self: Cli) -> None:
59+
def parse_args(self) -> None:
6060
"""Start parsing args passed from Cli."""
6161
args, pending_logs = Parser().parse_args()
6262
self.args = vars(args)
6363
self.pending_logs = pending_logs
6464

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

70-
def run(self: Cli) -> None:
70+
def run(self) -> None:
7171
"""Dispatch work to correct subcommand class."""
7272
self.output.debug(msg=f"parsed args {self.args!s}")
7373
subcommand = self.args["subcommand"]

src/ansible_creator/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class Config:
5050
type: str = ""
5151
path: str = ""
5252

53-
def __post_init__(self: Config) -> None:
53+
def __post_init__(self) -> None:
5454
"""Post process config values."""
5555
if self.project == "ansible-project":
5656
object.__setattr__(self, "project", "playbook")

src/ansible_creator/exceptions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
class CreatorError(Exception):
77
"""Class representing exceptions raised from creator code."""
88

9-
def __init__(self: CreatorError, message: str) -> None:
9+
def __init__(self, message: str) -> None:
1010
"""Instantiate an object of this class.
1111
1212
Args:
@@ -16,7 +16,7 @@ def __init__(self: CreatorError, message: str) -> None:
1616
self._message = message
1717

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

32-
def __str__(self: CreatorError) -> str:
32+
def __str__(self) -> str:
3333
"""Return a string representation of the exception.
3434
3535
Returns:

0 commit comments

Comments
 (0)