Skip to content

Commit

Permalink
style: apply ruff format
Browse files Browse the repository at this point in the history
  • Loading branch information
neithere committed Jun 16, 2024
1 parent 3b3a320 commit a5d556a
Show file tree
Hide file tree
Showing 23 changed files with 44 additions and 50 deletions.
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Configuration file for the Sphinx documentation builder."""

import os
import sys
from datetime import date
Expand Down
7 changes: 0 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
1 change: 1 addition & 0 deletions src/argh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Argh
~~~~
"""

#
# Copyright © 2010—2023 Andrey Mikhaylenko and contributors
#
Expand Down
10 changes: 5 additions & 5 deletions src/argh/assembling.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
Functions and classes to properly assemble your commands in a parser.
"""

import inspect
import textwrap
import warnings
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions src/argh/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def func(...):
...
"""

import logging
import os
from argparse import ArgumentParser
Expand Down
1 change: 1 addition & 0 deletions src/argh/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
Constants
~~~~~~~~~
"""

import argparse

__all__ = (
Expand Down
1 change: 1 addition & 0 deletions src/argh/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
Command decorators
~~~~~~~~~~~~~~~~~~
"""

from typing import Callable, List, Optional

from argh.constants import (
Expand Down
1 change: 1 addition & 0 deletions src/argh/dispatching.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
Dispatching
~~~~~~~~~~~
"""

import argparse
import inspect
import io
Expand Down
1 change: 1 addition & 0 deletions src/argh/dto.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
1 change: 1 addition & 0 deletions src/argh/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
Helpers
~~~~~~~
"""

import argparse
from typing import Optional, Sequence

Expand Down
1 change: 1 addition & 0 deletions src/argh/interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
Interaction
~~~~~~~~~~~
"""

from typing import Optional

__all__ = ["confirm"]
Expand Down
16 changes: 6 additions & 10 deletions src/argh/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
Utilities
~~~~~~~~~
"""

import argparse
import re
from typing import Tuple
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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): ...
1 change: 1 addition & 0 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Common stuff for tests
~~~~~~~~~~~~~~~~~~~~~~
"""

import io
import os
import sys
Expand Down
16 changes: 6 additions & 10 deletions tests/test_assembling.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Unit Tests For Assembling Phase
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""

import argparse
from typing import Literal, Optional
from unittest.mock import MagicMock, call, patch
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions tests/test_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""

from unittest.mock import patch

import argh
Expand Down
1 change: 1 addition & 0 deletions tests/test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Unit Tests For Decorators
~~~~~~~~~~~~~~~~~~~~~~~~~
"""

import pytest

import argh
Expand Down
7 changes: 3 additions & 4 deletions tests/test_dispatching.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Dispatching tests
~~~~~~~~~~~~~~~~~
"""

import argparse
import io
from unittest.mock import Mock, patch
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 5 additions & 8 deletions tests/test_dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -75,8 +73,7 @@ def stub_completer_two():
)


class TestGetAllKwargs:
...
class TestGetAllKwargs: ...


def test_make_from_kwargs_minimal() -> None:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Integration Tests
~~~~~~~~~~~~~~~~~
"""

import argparse
import re
import sys
Expand Down Expand Up @@ -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")

Expand Down
1 change: 1 addition & 0 deletions tests/test_interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Interaction Tests
~~~~~~~~~~~~~~~~~
"""

import unittest.mock as mock

import argh
Expand Down
3 changes: 1 addition & 2 deletions tests/test_mapping_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]")
Expand Down
4 changes: 2 additions & 2 deletions tests/test_regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Regression tests
~~~~~~~~~~~~~~~~
"""

import sys
from typing import List, Optional, TextIO

Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""

from argparse import ArgumentParser, _SubParsersAction

import pytest
Expand Down

0 comments on commit a5d556a

Please sign in to comment.