diff options
| -rw-r--r-- | patternutils/commands/pjson.py | 10 | ||||
| -rw-r--r-- | patternutils/commands/targs.py | 11 | ||||
| -rw-r--r-- | patternutils/commands/tln.py | 13 | ||||
| -rw-r--r-- | patternutils/commands/tmv.py | 14 |
4 files changed, 30 insertions, 18 deletions
diff --git a/patternutils/commands/pjson.py b/patternutils/commands/pjson.py index 12469ba..cbc87c9 100644 --- a/patternutils/commands/pjson.py +++ b/patternutils/commands/pjson.py @@ -1,6 +1,7 @@ import json import re -from typing import Pattern +from collections.abc import Iterable +from typing import Any, Pattern, TextIO import click @@ -67,7 +68,7 @@ def apply_regex( def pjson( key: str, regex_pattern: str, - read_from: click.File, + read_from: TextIO, stream: bool, abort_on_no_key: bool, abort_on_no_match: bool, @@ -84,10 +85,11 @@ def pjson( click.secho(e.msg, fg="red", err=True) raise SystemExit + data: Iterable[dict[str, Any]] if stream: - data = map(utils.json_loads, read_from) # type: ignore + data = map(utils.json_loads, read_from) else: - data = utils.json_loads(read_from.read()) # type: ignore + data = utils.json_loads(read_from.read()) matches = [] diff --git a/patternutils/commands/targs.py b/patternutils/commands/targs.py index 2df7968..a1a159b 100644 --- a/patternutils/commands/targs.py +++ b/patternutils/commands/targs.py @@ -4,7 +4,8 @@ import multiprocessing import os import shlex import subprocess -from typing import Callable +from collections.abc import Iterable +from typing import Any, Callable, TextIO import click @@ -75,7 +76,7 @@ def run_command( @click.argument("command") def targs( command: str, - read_from: click.File, + read_from: TextIO, shell: bool, template_engine: template.TemplateEngines, max_procs: int, @@ -93,11 +94,11 @@ def targs( --stream option is used), which are then supplied to the templating engine, to generate the command to run. """ - + data: Iterable[dict[str, Any]] if stream: - data = map(utils.json_loads, read_from) # type: ignore + data = map(utils.json_loads, read_from) else: - data = utils.json_loads(read_from.read()) # type: ignore + data = utils.json_loads(read_from.read()) if use_predefined_template: try: diff --git a/patternutils/commands/tln.py b/patternutils/commands/tln.py index ece5b75..8d58342 100644 --- a/patternutils/commands/tln.py +++ b/patternutils/commands/tln.py @@ -1,6 +1,8 @@ import json import os import os.path +from collections.abc import Iterable +from typing import Any, TextIO import click @@ -93,7 +95,7 @@ def tln( symbolic: bool, template_engine: template.TemplateEngines, use_predefined_template: bool, - read_from: click.File, + read_from: TextIO, key: str, stream: bool, abort_on_path_exist: bool, @@ -101,14 +103,17 @@ def tln( verbose: bool, ) -> None: + data: Iterable[dict[str, Any]] if stream: - data = map(utils.json_loads, read_from) # type: ignore + data = map(utils.json_loads, read_from) else: - data = utils.json_loads(read_from.read()) # type: ignore + data = utils.json_loads(read_from.read()) if use_predefined_template: try: - output_pattern, template_engine = config.load_template(output_pattern, "tln") + output_pattern, template_engine = config.load_template( + output_pattern, "tln" + ) except FileNotFoundError: click.secho(f"Template {output_pattern} not found!", fg="red", err=True) raise SystemExit diff --git a/patternutils/commands/tmv.py b/patternutils/commands/tmv.py index 6ce45ed..0ddbbd2 100644 --- a/patternutils/commands/tmv.py +++ b/patternutils/commands/tmv.py @@ -1,6 +1,8 @@ import json import os.path import shutil +from collections.abc import Iterable +from typing import Any, TextIO import click @@ -83,13 +85,12 @@ def tmv( template_engine: template.TemplateEngines, abort_on_path_exist: bool, use_predefined_template: bool, - read_from: click.File, + read_from: TextIO, key: str, stream: bool, dry_run: bool, verbose: bool, ) -> None: - """Rename files based on the OUTPUT_PATTERN. It reads in a JSON list containing objects or a stream of objects (if the @@ -99,14 +100,17 @@ def tmv( generate the new filename. """ + data: Iterable[dict[str, Any]] if stream: - data = map(utils.json_loads, read_from) # type: ignore + data = map(utils.json_loads, read_from) else: - data = utils.json_loads(read_from.read()) # type: ignore + data = utils.json_loads(read_from.read()) if use_predefined_template: try: - output_pattern, template_engine = config.load_template(output_pattern, "tmv") + output_pattern, template_engine = config.load_template( + output_pattern, "tmv" + ) except FileNotFoundError: click.secho(f"Template {output_pattern} not found!", fg="red", err=True) raise SystemExit |
