Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ repos:
hooks:
- id: flake8

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1
hooks:
- id: mypy

- repo: https://github.com/PyCQA/bandit
rev: 1.7.4
hooks:
Expand Down
6 changes: 5 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Version 0.30.0

Backwards incompatible changes:

- Removed previously deprecated features:
- Removed previously deprecated features (#184 → #188):

- argument help string in annotations — reserved for type hints;
- `argh.SUPPORTS_ALIASES`;
Expand All @@ -18,6 +18,10 @@ Backwards incompatible changes:
Note: the `pre_call` hack was scheduled to be removed but due to requests it
will remain until a replacement is implemented.

Enhancements:

- Added type annotations to existing Argh code (#185 → #189).

Version 0.29.4
--------------

Expand Down
26 changes: 13 additions & 13 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ A very simple application with one command:

import argh

def main():
def main() -> str:
return 'Hello world'

argh.dispatch_command(main)
Expand Down Expand Up @@ -148,9 +148,9 @@ A potentially modular application with more control over the process:
"Returns given word as is."
return text

def greet(name, greeting='Hello'):
def greet(name, greeting: str = "Hello") -> str:
"Greets the user with given name. The greeting is customizable."
return f'{greeting}, {name}!'
return f"{greeting}, {name}!"

# assembling:

Expand All @@ -159,7 +159,7 @@ A potentially modular application with more control over the process:

# dispatching:

if __name__ == '__main__':
if __name__ == "__main__":
parser.dispatch()

.. code-block:: bash
Expand Down Expand Up @@ -203,26 +203,26 @@ enough; in these cases the powerful API of `argparse` is also available:

.. code-block:: python

@arg('text', default='hello world', nargs='+', help='The message')
def echo(text):
@arg("text", default="hello world", nargs="+", help="The message")
def echo(text: str) -> None:
print text

The approaches can be safely combined even up to this level:

.. code-block:: python

# adding help to `foo` which is in the function signature:
@arg('foo', help='blah')
@arg("foo", help="blah")
# these are not in the signature so they go to **kwargs:
@arg('baz')
@arg('-q', '--quux')
@arg("baz")
@arg("-q", "--quux")
# the function itself:
def cmd(foo, bar=1, *args, **kwargs):
def cmd(foo: str, bar: int = 1, *args, **kwargs) -> Iterator[str]:
yield foo
yield bar
yield ', '.join(args)
yield kwargs['baz']
yield kwargs['quux']
yield ", ".join(args)
yield kwargs["baz"]
yield kwargs["quux"]

Links
-----
Expand Down
6 changes: 3 additions & 3 deletions docs/source/cookbook.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ Use `nargs` from argparse by amending the function signature with the

.. code-block:: python

@argh.arg('-p', '--patterns', nargs='*')
def cmd(patterns=None):
distros = ('abc', 'xyz')
@argh.arg("-p", "--patterns", nargs="*")
def cmd(patterns: list[str] | None = None) -> list:
distros = ("abc", "xyz")
return [d for d in distros if not patterns
or any(p in d for p in patterns)]

Expand Down
12 changes: 6 additions & 6 deletions docs/source/subparsers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ The equivalent code without `Argh` would be::
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers()

foo_parser = subparsers.add_parser('foo')
foo_parser = subparsers.add_parser("foo")
foo_parser.set_defaults(function=foo)

bar_parser = subparsers.add_parser('bar')
bar_parser = subparsers.add_parser("bar")
bar_parser.set_defaults(function=bar)

args = parser.parse_args()
Expand All @@ -31,7 +31,7 @@ The equivalent code without `Argh` would be::
Now consider this expression::

parser = ArghParser()
parser.add_commands([bar, quux], group_name='foo')
parser.add_commands([bar, quux], group_name="foo")
parser.dispatch()

It produces a command hierarchy for the command-line expressions ``foo bar``
Expand All @@ -44,13 +44,13 @@ to write something like this (generic argparse API)::
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers()

foo_parser = subparsers.add_parser('foo')
foo_parser = subparsers.add_parser("foo")
foo_subparsers = foo_parser.add_subparsers()

foo_bar_parser = foo_subparsers.add_parser('bar')
foo_bar_parser = foo_subparsers.add_parser("bar")
foo_bar_parser.set_defaults(function=bar)

foo_quux_parser = foo_subparsers.add_parser('quux')
foo_quux_parser = foo_subparsers.add_parser("quux")
foo_quux_parser.set_defaults(function=quux)

args = parser.parse_args()
Expand Down
Loading