From a5d556a778426a82cb8bb66150fe6c6d49ea9b6d Mon Sep 17 00:00:00 2001 From: Andy Mikhaylenko Date: Sun, 16 Jun 2024 22:57:29 +0200 Subject: [PATCH] style: apply `ruff format` --- docs/conf.py | 1 + pyproject.toml | 7 ------- src/argh/__init__.py | 1 + src/argh/assembling.py | 10 +++++----- src/argh/completion.py | 1 + src/argh/constants.py | 1 + src/argh/decorators.py | 1 + src/argh/dispatching.py | 1 + src/argh/dto.py | 1 + src/argh/helpers.py | 1 + src/argh/interaction.py | 1 + src/argh/utils.py | 16 ++++++---------- tests/base.py | 1 + tests/test_assembling.py | 16 ++++++---------- tests/test_completion.py | 1 + tests/test_decorators.py | 1 + tests/test_dispatching.py | 7 +++---- tests/test_dto.py | 13 +++++-------- tests/test_integration.py | 4 ++-- tests/test_interaction.py | 1 + tests/test_mapping_policies.py | 3 +-- tests/test_regressions.py | 4 ++-- tests/test_utils.py | 1 + 23 files changed, 44 insertions(+), 50 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index c54bf35..bb8c1ea 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,4 +1,5 @@ """Configuration file for the Sphinx documentation builder.""" + import os import sys from datetime import date diff --git a/pyproject.toml b/pyproject.toml index dd25a2f..83e4761 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -72,13 +72,6 @@ linters = [ [tool.distutils.bdist_wheel] universal = 1 -[tool.isort] -multi_line_output = 3 -profile = "black" - -[tool.black] -target-version = ["py38", "py39", "py310", "py311", "py312"] - [tool.bandit] exclude_dirs = ["tests"] diff --git a/src/argh/__init__.py b/src/argh/__init__.py index 5d6b048..875ec44 100644 --- a/src/argh/__init__.py +++ b/src/argh/__init__.py @@ -2,6 +2,7 @@ Argh ~~~~ """ + # # Copyright © 2010—2023 Andrey Mikhaylenko and contributors # diff --git a/src/argh/assembling.py b/src/argh/assembling.py index 7a690ea..fdfc4a0 100644 --- a/src/argh/assembling.py +++ b/src/argh/assembling.py @@ -13,6 +13,7 @@ Functions and classes to properly assemble your commands in a parser. """ + import inspect import textwrap import warnings @@ -517,9 +518,9 @@ def _merge_inferred_and_declared_args( # arguments inferred from function signature for parser_add_argument_spec in inferred_args: - specs_by_func_arg_name[ - parser_add_argument_spec.func_arg_name - ] = parser_add_argument_spec + specs_by_func_arg_name[parser_add_argument_spec.func_arg_name] = ( + parser_add_argument_spec + ) # arguments declared via @arg decorator for declared_spec in declared_args: @@ -734,8 +735,7 @@ def add_subcommands( add_commands(parser, functions, group_name=group_name, group_kwargs=group_kwargs) -class ArgumentNameMappingError(AssemblingError): - ... +class ArgumentNameMappingError(AssemblingError): ... class TypingHintArgSpecGuesser: diff --git a/src/argh/completion.py b/src/argh/completion.py index 93b5f37..f2069be 100644 --- a/src/argh/completion.py +++ b/src/argh/completion.py @@ -57,6 +57,7 @@ def func(...): ... """ + import logging import os from argparse import ArgumentParser diff --git a/src/argh/constants.py b/src/argh/constants.py index 9bf1672..07a21d8 100644 --- a/src/argh/constants.py +++ b/src/argh/constants.py @@ -11,6 +11,7 @@ Constants ~~~~~~~~~ """ + import argparse __all__ = ( diff --git a/src/argh/decorators.py b/src/argh/decorators.py index 8913a95..aaa20b7 100644 --- a/src/argh/decorators.py +++ b/src/argh/decorators.py @@ -11,6 +11,7 @@ Command decorators ~~~~~~~~~~~~~~~~~~ """ + from typing import Callable, List, Optional from argh.constants import ( diff --git a/src/argh/dispatching.py b/src/argh/dispatching.py index ef413f6..a5233d4 100644 --- a/src/argh/dispatching.py +++ b/src/argh/dispatching.py @@ -11,6 +11,7 @@ Dispatching ~~~~~~~~~~~ """ + import argparse import inspect import io diff --git a/src/argh/dto.py b/src/argh/dto.py index e4a32cd..eb2d1c6 100644 --- a/src/argh/dto.py +++ b/src/argh/dto.py @@ -1,6 +1,7 @@ """ Data transfer objects for internal usage. """ + from dataclasses import dataclass, field from typing import Any, Callable, Dict, List, Optional, Type, Union diff --git a/src/argh/helpers.py b/src/argh/helpers.py index 154ff7c..770fdca 100644 --- a/src/argh/helpers.py +++ b/src/argh/helpers.py @@ -11,6 +11,7 @@ Helpers ~~~~~~~ """ + import argparse from typing import Optional, Sequence diff --git a/src/argh/interaction.py b/src/argh/interaction.py index ab8f0e3..d06ce28 100644 --- a/src/argh/interaction.py +++ b/src/argh/interaction.py @@ -11,6 +11,7 @@ Interaction ~~~~~~~~~~~ """ + from typing import Optional __all__ = ["confirm"] diff --git a/src/argh/utils.py b/src/argh/utils.py index 3f7d42d..40aa40d 100644 --- a/src/argh/utils.py +++ b/src/argh/utils.py @@ -11,6 +11,7 @@ Utilities ~~~~~~~~~ """ + import argparse import re from typing import Tuple @@ -59,8 +60,7 @@ def unindent(text: str) -> str: return re.sub(rf"(^|\n) {{{depth}}}", "\\1", text) -class SubparsersNotDefinedError(Exception): - ... +class SubparsersNotDefinedError(Exception): ... def naive_guess_func_arg_name(option_strings: Tuple[str, ...]) -> str: @@ -89,17 +89,13 @@ def _opt_to_func_arg_name(opt: str) -> str: ) -class ArghError(Exception): - ... +class ArghError(Exception): ... -class CliArgToFuncArgGuessingError(ArghError): - ... +class CliArgToFuncArgGuessingError(ArghError): ... -class TooManyPositionalArgumentNames(CliArgToFuncArgGuessingError): - ... +class TooManyPositionalArgumentNames(CliArgToFuncArgGuessingError): ... -class MixedPositionalAndOptionalArgsError(CliArgToFuncArgGuessingError): - ... +class MixedPositionalAndOptionalArgsError(CliArgToFuncArgGuessingError): ... diff --git a/tests/base.py b/tests/base.py index d8e68c7..7710443 100644 --- a/tests/base.py +++ b/tests/base.py @@ -2,6 +2,7 @@ Common stuff for tests ~~~~~~~~~~~~~~~~~~~~~~ """ + import io import os import sys diff --git a/tests/test_assembling.py b/tests/test_assembling.py index 23c17a0..0b82eb5 100644 --- a/tests/test_assembling.py +++ b/tests/test_assembling.py @@ -2,6 +2,7 @@ Unit Tests For Assembling Phase ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ """ + import argparse from typing import Literal, Optional from unittest.mock import MagicMock, call, patch @@ -85,8 +86,7 @@ def test_guess_action_from_default(): def test_positional_with_default_int(): - def func(pos_int_default=123): - ... + def func(pos_int_default=123): ... parser = argh.ArghParser(prog="test") parser.set_default_command( @@ -97,8 +97,7 @@ def func(pos_int_default=123): def test_positional_with_default_bool(): - def func(pos_bool_default=False): - ... + def func(pos_bool_default=False): ... parser = argh.ArghParser(prog="test") parser.set_default_command( @@ -500,8 +499,7 @@ def func(): def test_set_default_command__varkwargs_sharing_prefix(): - def func(*, alpha: str = "Alpha", aleph: str = "Aleph"): - ... + def func(*, alpha: str = "Alpha", aleph: str = "Aleph"): ... parser = argh.ArghParser() parser.add_argument = MagicMock() @@ -767,11 +765,9 @@ def test_is_positional(): def test_typing_hints_only_used_when_arg_deco_not_used(): @argh.arg("foo", type=int) - def func_decorated(foo: Optional[float]): - ... + def func_decorated(foo: Optional[float]): ... - def func_undecorated(bar: Optional[float]): - ... + def func_undecorated(bar: Optional[float]): ... parser = argparse.ArgumentParser() parser.add_argument = MagicMock() diff --git a/tests/test_completion.py b/tests/test_completion.py index afb4b37..70548ba 100644 --- a/tests/test_completion.py +++ b/tests/test_completion.py @@ -3,6 +3,7 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ """ + from unittest.mock import patch import argh diff --git a/tests/test_decorators.py b/tests/test_decorators.py index 7c9b7cb..9bf9e67 100644 --- a/tests/test_decorators.py +++ b/tests/test_decorators.py @@ -2,6 +2,7 @@ Unit Tests For Decorators ~~~~~~~~~~~~~~~~~~~~~~~~~ """ + import pytest import argh diff --git a/tests/test_dispatching.py b/tests/test_dispatching.py index 1bfaf72..d60556c 100644 --- a/tests/test_dispatching.py +++ b/tests/test_dispatching.py @@ -2,6 +2,7 @@ Dispatching tests ~~~~~~~~~~~~~~~~~ """ + import argparse import io from unittest.mock import Mock, patch @@ -198,8 +199,7 @@ def hit(): def test_dispatch_command_naming_policy( parser_cls_mock, set_default_command_mock, dispatch_mock ): - def func(): - ... + def func(): ... parser_mock = Mock() parser_cls_mock.return_value = parser_mock @@ -234,8 +234,7 @@ def func(): def test_dispatch_commands_naming_policy( parser_cls_mock, add_commands_mock, dispatch_mock ): - def func(): - ... + def func(): ... parser_mock = Mock() parser_cls_mock.return_value = parser_mock diff --git a/tests/test_dto.py b/tests/test_dto.py index b5e3c3a..86c4b06 100644 --- a/tests/test_dto.py +++ b/tests/test_dto.py @@ -2,12 +2,12 @@ Unit Tests For the Argument DTO ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ """ + from argh.dto import ParserAddArgumentSpec def test_update_empty_dto() -> None: - def stub_completer(): - ... + def stub_completer(): ... dto = ParserAddArgumentSpec( func_arg_name="foo", @@ -37,11 +37,9 @@ def stub_completer(): def test_update_full_dto() -> None: - def stub_completer_one(): - ... + def stub_completer_one(): ... - def stub_completer_two(): - ... + def stub_completer_two(): ... dto = ParserAddArgumentSpec( func_arg_name="foo", @@ -75,8 +73,7 @@ def stub_completer_two(): ) -class TestGetAllKwargs: - ... +class TestGetAllKwargs: ... def test_make_from_kwargs_minimal() -> None: diff --git a/tests/test_integration.py b/tests/test_integration.py index 7764160..8839265 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -2,6 +2,7 @@ Integration Tests ~~~~~~~~~~~~~~~~~ """ + import argparse import re import sys @@ -831,8 +832,7 @@ def cmd(*, foo=1): def test_add_commands_unknown_name_mapping_policy(): - def func(foo): - ... + def func(foo): ... parser = argh.ArghParser(prog="myapp") diff --git a/tests/test_interaction.py b/tests/test_interaction.py index f1dee89..5d903e6 100644 --- a/tests/test_interaction.py +++ b/tests/test_interaction.py @@ -2,6 +2,7 @@ Interaction Tests ~~~~~~~~~~~~~~~~~ """ + import unittest.mock as mock import argh diff --git a/tests/test_mapping_policies.py b/tests/test_mapping_policies.py index db67e71..e77e122 100644 --- a/tests/test_mapping_policies.py +++ b/tests/test_mapping_policies.py @@ -15,8 +15,7 @@ @pytest.mark.parametrize("name_mapping_policy", POLICIES) def test_no_args(name_mapping_policy) -> None: - def func() -> None: - ... + def func() -> None: ... parser = _make_parser_for_function(func, name_mapping_policy=name_mapping_policy) assert_usage(parser, "usage: test [-h]") diff --git a/tests/test_regressions.py b/tests/test_regressions.py index 562a042..343da81 100644 --- a/tests/test_regressions.py +++ b/tests/test_regressions.py @@ -2,6 +2,7 @@ Regression tests ~~~~~~~~~~~~~~~~ """ + import sys from typing import List, Optional, TextIO @@ -166,8 +167,7 @@ def test_regression_issue204(): We should avoid `deepcopy()` in standard operations. """ - def func(*, x: TextIO = sys.stdout) -> None: - ... + def func(*, x: TextIO = sys.stdout) -> None: ... parser = DebugArghParser() parser.set_default_command(func) diff --git a/tests/test_utils.py b/tests/test_utils.py index df91f47..2b9d17f 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -3,6 +3,7 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ """ + from argparse import ArgumentParser, _SubParsersAction import pytest