From f4deaab196d1c5e97e1a85a38059523cbae7cad4 Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Sat, 16 Sep 2023 10:48:51 +0200 Subject: [PATCH] Fix some lint violations before enforcing them --- mkdocs_click/_docs.py | 17 ++++++++--------- mkdocs_click/_extension.py | 6 ++++-- mkdocs_click/_loader.py | 3 +++ mkdocs_click/_processing.py | 4 +++- tests/test_docs.py | 2 +- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/mkdocs_click/_docs.py b/mkdocs_click/_docs.py index ddff48f..bf86c53 100644 --- a/mkdocs_click/_docs.py +++ b/mkdocs_click/_docs.py @@ -1,9 +1,11 @@ # (C) Datadog, Inc. 2020-present # All rights reserved # Licensed under the Apache license (see LICENSE) +from __future__ import annotations + import inspect -from contextlib import contextmanager, ExitStack -from typing import Iterator, List, cast, Optional +from contextlib import ExitStack, contextmanager +from typing import Iterator, cast import click from markdown.extensions.toc import slugify @@ -41,7 +43,7 @@ def make_command_docs( def _recursively_make_command_docs( prog_name: str, command: click.BaseCommand, - parent: click.Context = None, + parent: click.Context | None = None, depth: int = 0, style: str = "plain", remove_ascii_art: bool = False, @@ -87,13 +89,11 @@ def _recursively_make_command_docs( ) -def _build_command_context( - prog_name: str, command: click.BaseCommand, parent: Optional[click.Context] -) -> click.Context: +def _build_command_context(prog_name: str, command: click.BaseCommand, parent: click.Context | None) -> click.Context: return click.Context(cast(click.Command, command), info_name=prog_name, parent=parent) -def _get_sub_commands(command: click.Command, ctx: click.Context) -> List[click.Command]: +def _get_sub_commands(command: click.Command, ctx: click.Context) -> list[click.Command]: """Return subcommands of a Click command.""" subcommands = getattr(command, "commands", {}) if subcommands: @@ -328,12 +328,11 @@ def _make_table_options(ctx: click.Context, show_hidden: bool = False) -> Iterat def _make_subcommands_links( - subcommands: List[click.Command], + subcommands: list[click.Command], parent: click.Context, has_attr_list: bool, show_hidden: bool, ) -> Iterator[str]: - yield "**Subcommands**" yield "" for command in subcommands: diff --git a/mkdocs_click/_extension.py b/mkdocs_click/_extension.py index 4fd5989..f799c77 100644 --- a/mkdocs_click/_extension.py +++ b/mkdocs_click/_extension.py @@ -1,7 +1,9 @@ # (C) Datadog, Inc. 2020-present # All rights reserved # Licensed under the Apache license (see LICENSE) -from typing import Any, Iterator, List +from __future__ import annotations + +from typing import Any, Iterator from markdown.extensions import Extension from markdown.extensions.attr_list import AttrListExtension @@ -48,7 +50,7 @@ def __init__(self, md: Any) -> None: super().__init__(md) self._has_attr_list = any(isinstance(ext, AttrListExtension) for ext in md.registeredExtensions) - def run(self, lines: List[str]) -> List[str]: + def run(self, lines: list[str]) -> list[str]: return list( replace_blocks( lines, diff --git a/mkdocs_click/_loader.py b/mkdocs_click/_loader.py index da141be..102d478 100644 --- a/mkdocs_click/_loader.py +++ b/mkdocs_click/_loader.py @@ -1,10 +1,13 @@ # (C) Datadog, Inc. 2020-present # All rights reserved # Licensed under the Apache license (see LICENSE) +from __future__ import annotations + import importlib from typing import Any import click + from ._exceptions import MkDocsClickException diff --git a/mkdocs_click/_processing.py b/mkdocs_click/_processing.py index a816eb7..e620d4b 100644 --- a/mkdocs_click/_processing.py +++ b/mkdocs_click/_processing.py @@ -1,6 +1,8 @@ # (C) Datadog, Inc. 2020-present # All rights reserved # Licensed under the Apache license (see LICENSE) +from __future__ import annotations + import re from typing import Callable, Iterable, Iterator @@ -28,7 +30,7 @@ def replace_blocks(lines: Iterable[str], title: str, replace: Callable[..., Iter key = match.group("key") value = match.group("value") or "" if value.lower() in ["true", "false"]: - value = True if value.lower() == "true" else False + value = value.lower() == "true" options[key] = value continue diff --git a/tests/test_docs.py b/tests/test_docs.py index fe98287..ede4418 100644 --- a/tests/test_docs.py +++ b/tests/test_docs.py @@ -7,7 +7,7 @@ import click import pytest -from mkdocs_click._docs import make_command_docs, _show_options +from mkdocs_click._docs import _show_options, make_command_docs from mkdocs_click._exceptions import MkDocsClickException