trivial: Use objects from collections.abc
Change-Id: I0acf36b70513bccda33359f415d3d5e968aa7fcc Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
"""Overrides of standard argparse behavior."""
|
||||
|
||||
import argparse
|
||||
import collections.abc
|
||||
from collections.abc import Iterable
|
||||
import typing as ty
|
||||
import warnings
|
||||
|
||||
@@ -42,9 +42,7 @@ class ArgumentParser(autopage.argparse.ArgumentParser):
|
||||
def _handle_conflict_ignore(
|
||||
self,
|
||||
action: argparse.Action,
|
||||
conflicting_actions: collections.abc.Iterable[
|
||||
tuple[str, argparse.Action]
|
||||
],
|
||||
conflicting_actions: Iterable[tuple[str, argparse.Action]],
|
||||
) -> None:
|
||||
_handle_conflict_ignore(
|
||||
self,
|
||||
@@ -58,7 +56,7 @@ def _handle_conflict_ignore(
|
||||
container: argparse._ActionsContainer,
|
||||
option_string_actions: dict[str, argparse.Action],
|
||||
new_action: argparse.Action,
|
||||
conflicting_actions: collections.abc.Iterable[tuple[str, argparse.Action]],
|
||||
conflicting_actions: Iterable[tuple[str, argparse.Action]],
|
||||
) -> None:
|
||||
# Remember the option strings the new action starts with so we can
|
||||
# restore them as part of error reporting if we need to.
|
||||
@@ -107,9 +105,7 @@ class _ArgumentGroup(argparse._ArgumentGroup):
|
||||
def _handle_conflict_ignore(
|
||||
self,
|
||||
action: argparse.Action,
|
||||
conflicting_actions: collections.abc.Iterable[
|
||||
tuple[str, argparse.Action]
|
||||
],
|
||||
conflicting_actions: Iterable[tuple[str, argparse.Action]],
|
||||
) -> None:
|
||||
_handle_conflict_ignore(
|
||||
self,
|
||||
@@ -141,9 +137,7 @@ class _MutuallyExclusiveGroup(argparse._MutuallyExclusiveGroup):
|
||||
def _handle_conflict_ignore(
|
||||
self,
|
||||
action: argparse.Action,
|
||||
conflicting_actions: collections.abc.Iterable[
|
||||
tuple[str, argparse.Action]
|
||||
],
|
||||
conflicting_actions: Iterable[tuple[str, argparse.Action]],
|
||||
) -> None:
|
||||
_handle_conflict_ignore(
|
||||
self,
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
"""Discover and lookup command plugins."""
|
||||
|
||||
import collections.abc
|
||||
from collections.abc import Iterable, Iterator
|
||||
import importlib.metadata
|
||||
import logging
|
||||
from typing import TypeAlias
|
||||
@@ -83,7 +83,7 @@ class CommandManager:
|
||||
namespace: str | None = None,
|
||||
convert_underscores: bool = True,
|
||||
*,
|
||||
ignored_modules: collections.abc.Iterable[str] | None = None,
|
||||
ignored_modules: Iterable[str] | None = None,
|
||||
) -> None:
|
||||
self.namespace = namespace
|
||||
self.convert_underscores = convert_underscores
|
||||
@@ -101,7 +101,7 @@ class CommandManager:
|
||||
|
||||
@staticmethod
|
||||
def _is_module_ignored(
|
||||
module_name: str, ignored_modules: collections.abc.Iterable[str]
|
||||
module_name: str, ignored_modules: Iterable[str]
|
||||
) -> bool:
|
||||
# given module_name = 'foo.bar.baz:wow', we expect to match any of
|
||||
# the following ignores: foo.bar.baz:wow, foo.bar.baz, foo.bar, foo
|
||||
@@ -175,7 +175,7 @@ class CommandManager:
|
||||
|
||||
def __iter__(
|
||||
self,
|
||||
) -> collections.abc.Iterator[tuple[str, EntryPointT]]:
|
||||
) -> Iterator[tuple[str, EntryPointT]]:
|
||||
return iter(self.commands.items())
|
||||
|
||||
def add_command(
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
import abc
|
||||
import argparse
|
||||
import collections.abc
|
||||
from collections.abc import Iterable, Iterator, Sequence
|
||||
from itertools import compress
|
||||
import typing as ty
|
||||
|
||||
@@ -106,7 +106,7 @@ class DisplayCommandBase(
|
||||
def produce_output(
|
||||
self,
|
||||
parsed_args: argparse.Namespace,
|
||||
column_names: collections.abc.Sequence[str],
|
||||
column_names: Sequence[str],
|
||||
data: ty.Any,
|
||||
) -> int:
|
||||
"""Use the formatter to generate the output.
|
||||
@@ -121,7 +121,7 @@ class DisplayCommandBase(
|
||||
def _generate_columns_and_selector(
|
||||
self,
|
||||
parsed_args: argparse.Namespace,
|
||||
column_names: collections.abc.Sequence[str],
|
||||
column_names: Sequence[str],
|
||||
) -> tuple[list[str], list[bool] | None]:
|
||||
"""Generate included columns and selector according to parsed args.
|
||||
|
||||
@@ -167,12 +167,8 @@ class DisplayCommandBase(
|
||||
def _run_after_hooks( # type: ignore[override]
|
||||
self,
|
||||
parsed_args: argparse.Namespace,
|
||||
data: tuple[
|
||||
collections.abc.Sequence[str], collections.abc.Iterable[ty.Any]
|
||||
],
|
||||
) -> tuple[
|
||||
collections.abc.Sequence[str], collections.abc.Iterable[ty.Any]
|
||||
]:
|
||||
data: tuple[Sequence[str], Iterable[ty.Any]],
|
||||
) -> tuple[Sequence[str], Iterable[ty.Any]]:
|
||||
"""Calls after() method of the hooks.
|
||||
|
||||
This method is intended to be called from the run() method after
|
||||
@@ -196,7 +192,7 @@ class DisplayCommandBase(
|
||||
|
||||
@staticmethod
|
||||
def _compress_iterable(
|
||||
iterable: collections.abc.Iterable[_T],
|
||||
selectors: collections.abc.Iterable[ty.Any],
|
||||
) -> collections.abc.Iterator[_T]:
|
||||
iterable: Iterable[_T],
|
||||
selectors: Iterable[ty.Any],
|
||||
) -> Iterator[_T]:
|
||||
return compress(iterable, selectors)
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
import abc
|
||||
import argparse
|
||||
import collections.abc
|
||||
from collections.abc import Iterable, Sequence
|
||||
import typing as ty
|
||||
|
||||
|
||||
@@ -36,8 +36,8 @@ class ListFormatter(Formatter, metaclass=abc.ABCMeta):
|
||||
@abc.abstractmethod
|
||||
def emit_list(
|
||||
self,
|
||||
column_names: collections.abc.Sequence[str],
|
||||
data: collections.abc.Iterable[collections.abc.Sequence[ty.Any]],
|
||||
column_names: Sequence[str],
|
||||
data: Iterable[Sequence[ty.Any]],
|
||||
stdout: ty.TextIO,
|
||||
parsed_args: argparse.Namespace,
|
||||
) -> None:
|
||||
@@ -63,8 +63,8 @@ class SingleFormatter(Formatter, metaclass=abc.ABCMeta):
|
||||
@abc.abstractmethod
|
||||
def emit_one(
|
||||
self,
|
||||
column_names: collections.abc.Sequence[str],
|
||||
data: collections.abc.Sequence[ty.Any],
|
||||
column_names: Sequence[str],
|
||||
data: Sequence[ty.Any],
|
||||
stdout: ty.TextIO,
|
||||
parsed_args: argparse.Namespace,
|
||||
) -> None:
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
"""Output formatters using csv format."""
|
||||
|
||||
import argparse
|
||||
import collections.abc
|
||||
from collections.abc import Iterable, Sequence
|
||||
import csv
|
||||
import os
|
||||
import typing as ty
|
||||
@@ -42,8 +42,8 @@ class CSVLister(base.ListFormatter):
|
||||
|
||||
def emit_list(
|
||||
self,
|
||||
column_names: collections.abc.Sequence[str],
|
||||
data: collections.abc.Iterable[collections.abc.Sequence[ty.Any]],
|
||||
column_names: Sequence[str],
|
||||
data: Iterable[Sequence[ty.Any]],
|
||||
stdout: ty.TextIO,
|
||||
parsed_args: argparse.Namespace,
|
||||
) -> None:
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
"""Output formatters for JSON."""
|
||||
|
||||
import argparse
|
||||
import collections.abc
|
||||
from collections.abc import Iterable, Sequence
|
||||
import json
|
||||
import typing as ty
|
||||
|
||||
@@ -33,8 +33,8 @@ class JSONFormatter(base.ListFormatter, base.SingleFormatter):
|
||||
|
||||
def emit_list(
|
||||
self,
|
||||
column_names: collections.abc.Sequence[str],
|
||||
data: collections.abc.Iterable[collections.abc.Sequence[ty.Any]],
|
||||
column_names: Sequence[str],
|
||||
data: Iterable[Sequence[ty.Any]],
|
||||
stdout: ty.TextIO,
|
||||
parsed_args: argparse.Namespace,
|
||||
) -> None:
|
||||
@@ -56,8 +56,8 @@ class JSONFormatter(base.ListFormatter, base.SingleFormatter):
|
||||
|
||||
def emit_one(
|
||||
self,
|
||||
column_names: collections.abc.Sequence[str],
|
||||
data: collections.abc.Sequence[ty.Any],
|
||||
column_names: Sequence[str],
|
||||
data: Sequence[ty.Any],
|
||||
stdout: ty.TextIO,
|
||||
parsed_args: argparse.Namespace,
|
||||
) -> None:
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
"""Output formatters using shell syntax."""
|
||||
|
||||
import argparse
|
||||
import collections.abc
|
||||
from collections.abc import Sequence
|
||||
import typing as ty
|
||||
|
||||
from cliff import columns
|
||||
@@ -44,8 +44,8 @@ class ShellFormatter(base.SingleFormatter):
|
||||
|
||||
def emit_one(
|
||||
self,
|
||||
column_names: collections.abc.Sequence[str],
|
||||
data: collections.abc.Sequence[ty.Any],
|
||||
column_names: Sequence[str],
|
||||
data: Sequence[ty.Any],
|
||||
stdout: ty.TextIO,
|
||||
parsed_args: argparse.Namespace,
|
||||
) -> None:
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
"""Output formatters using prettytable."""
|
||||
|
||||
import argparse
|
||||
import collections.abc
|
||||
from collections.abc import Iterable, Sequence
|
||||
import os
|
||||
import sys
|
||||
import typing as ty
|
||||
@@ -28,9 +28,7 @@ _T = ty.TypeVar('_T')
|
||||
|
||||
|
||||
def _format_row(
|
||||
row: collections.abc.Iterable[
|
||||
columns.FormattableColumn[ty.Any] | str | _T
|
||||
],
|
||||
row: Iterable[columns.FormattableColumn[ty.Any] | str | _T],
|
||||
) -> list[_T | str]:
|
||||
new_row = []
|
||||
for r in row:
|
||||
@@ -90,8 +88,8 @@ class TableFormatter(base.ListFormatter, base.SingleFormatter):
|
||||
def add_rows(
|
||||
self,
|
||||
table: prettytable.PrettyTable,
|
||||
column_names: collections.abc.Sequence[str],
|
||||
data: collections.abc.Iterable[collections.abc.Sequence[ty.Any]],
|
||||
column_names: Sequence[str],
|
||||
data: Iterable[Sequence[ty.Any]],
|
||||
) -> None:
|
||||
# Figure out the types of the columns in the
|
||||
# first row and set the alignment of the
|
||||
@@ -112,8 +110,8 @@ class TableFormatter(base.ListFormatter, base.SingleFormatter):
|
||||
|
||||
def emit_list(
|
||||
self,
|
||||
column_names: collections.abc.Sequence[str],
|
||||
data: collections.abc.Iterable[collections.abc.Sequence[ty.Any]],
|
||||
column_names: Sequence[str],
|
||||
data: Iterable[Sequence[ty.Any]],
|
||||
stdout: ty.TextIO,
|
||||
parsed_args: argparse.Namespace,
|
||||
) -> None:
|
||||
@@ -142,8 +140,8 @@ class TableFormatter(base.ListFormatter, base.SingleFormatter):
|
||||
|
||||
def emit_one(
|
||||
self,
|
||||
column_names: collections.abc.Sequence[str],
|
||||
data: collections.abc.Sequence[ty.Any],
|
||||
column_names: Sequence[str],
|
||||
data: Sequence[ty.Any],
|
||||
stdout: ty.TextIO,
|
||||
parsed_args: argparse.Namespace,
|
||||
) -> None:
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
"""Output formatters values only"""
|
||||
|
||||
import argparse
|
||||
import collections.abc
|
||||
from collections.abc import Iterable, Sequence
|
||||
import typing as ty
|
||||
|
||||
from cliff import columns
|
||||
@@ -26,8 +26,8 @@ class ValueFormatter(base.ListFormatter, base.SingleFormatter):
|
||||
|
||||
def emit_list(
|
||||
self,
|
||||
column_names: collections.abc.Sequence[str],
|
||||
data: collections.abc.Iterable[collections.abc.Sequence[ty.Any]],
|
||||
column_names: Sequence[str],
|
||||
data: Iterable[Sequence[ty.Any]],
|
||||
stdout: ty.TextIO,
|
||||
parsed_args: argparse.Namespace,
|
||||
) -> None:
|
||||
@@ -47,8 +47,8 @@ class ValueFormatter(base.ListFormatter, base.SingleFormatter):
|
||||
|
||||
def emit_one(
|
||||
self,
|
||||
column_names: collections.abc.Sequence[str],
|
||||
data: collections.abc.Sequence[ty.Any],
|
||||
column_names: Sequence[str],
|
||||
data: Sequence[ty.Any],
|
||||
stdout: ty.TextIO,
|
||||
parsed_args: argparse.Namespace,
|
||||
) -> None:
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
"""Output formatters using PyYAML."""
|
||||
|
||||
import argparse
|
||||
import collections.abc
|
||||
from collections.abc import Iterable, Sequence
|
||||
import typing as ty
|
||||
|
||||
from cliff import columns
|
||||
@@ -37,8 +37,8 @@ class YAMLFormatter(base.ListFormatter, base.SingleFormatter):
|
||||
|
||||
def emit_list(
|
||||
self,
|
||||
column_names: collections.abc.Sequence[str],
|
||||
data: collections.abc.Iterable[collections.abc.Sequence[ty.Any]],
|
||||
column_names: Sequence[str],
|
||||
data: Iterable[Sequence[ty.Any]],
|
||||
stdout: ty.TextIO,
|
||||
parsed_args: argparse.Namespace,
|
||||
) -> None:
|
||||
@@ -54,8 +54,8 @@ class YAMLFormatter(base.ListFormatter, base.SingleFormatter):
|
||||
|
||||
def emit_one(
|
||||
self,
|
||||
column_names: collections.abc.Sequence[str],
|
||||
data: collections.abc.Sequence[ty.Any],
|
||||
column_names: Sequence[str],
|
||||
data: Sequence[ty.Any],
|
||||
stdout: ty.TextIO,
|
||||
parsed_args: argparse.Namespace,
|
||||
) -> None:
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
# under the License.
|
||||
|
||||
import argparse
|
||||
import collections.abc
|
||||
from collections.abc import Sequence
|
||||
import inspect
|
||||
import traceback
|
||||
import typing as ty
|
||||
@@ -43,7 +43,7 @@ class HelpAction(argparse.Action):
|
||||
self,
|
||||
parser: argparse.ArgumentParser,
|
||||
namespace: argparse.Namespace,
|
||||
values: str | collections.abc.Sequence[ty.Any] | None,
|
||||
values: str | Sequence[ty.Any] | None,
|
||||
option_string: str | None = None,
|
||||
) -> None:
|
||||
app = self.default
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
import abc
|
||||
import argparse
|
||||
import collections.abc
|
||||
from collections.abc import Iterable, Sequence
|
||||
import logging
|
||||
import typing as ty
|
||||
|
||||
@@ -50,9 +50,7 @@ class Lister(
|
||||
@abc.abstractmethod
|
||||
def take_action(
|
||||
self, parsed_args: argparse.Namespace
|
||||
) -> tuple[
|
||||
collections.abc.Sequence[str], collections.abc.Iterable[ty.Any]
|
||||
]:
|
||||
) -> tuple[Sequence[str], Iterable[ty.Any]]:
|
||||
"""Run command.
|
||||
|
||||
Return a tuple containing the column names and an iterable containing
|
||||
@@ -94,8 +92,8 @@ class Lister(
|
||||
def produce_output(
|
||||
self,
|
||||
parsed_args: argparse.Namespace,
|
||||
column_names: collections.abc.Sequence[str],
|
||||
data: collections.abc.Iterable[collections.abc.Sequence[ty.Any]],
|
||||
column_names: Sequence[str],
|
||||
data: Iterable[Sequence[ty.Any]],
|
||||
) -> int:
|
||||
if parsed_args.sort_columns and self.need_sort_by_cliff:
|
||||
indexes = [
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
import abc
|
||||
import argparse
|
||||
import collections.abc
|
||||
from collections.abc import Iterable, Sequence
|
||||
import typing as ty
|
||||
|
||||
from cliff import display
|
||||
@@ -38,9 +38,7 @@ class ShowOne(
|
||||
@abc.abstractmethod
|
||||
def take_action(
|
||||
self, parsed_args: argparse.Namespace
|
||||
) -> tuple[
|
||||
collections.abc.Sequence[str], collections.abc.Iterable[ty.Any]
|
||||
]:
|
||||
) -> tuple[Sequence[str], Iterable[ty.Any]]:
|
||||
"""Run command.
|
||||
|
||||
Return a tuple containing the column names and an iterable containing
|
||||
@@ -50,8 +48,8 @@ class ShowOne(
|
||||
def produce_output(
|
||||
self,
|
||||
parsed_args: argparse.Namespace,
|
||||
column_names: collections.abc.Sequence[str],
|
||||
data: collections.abc.Sequence[ty.Any],
|
||||
column_names: Sequence[str],
|
||||
data: Sequence[ty.Any],
|
||||
) -> int:
|
||||
columns_to_include, selector = self._generate_columns_and_selector(
|
||||
parsed_args, column_names
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
# under the License.
|
||||
|
||||
import argparse
|
||||
import collections.abc
|
||||
from collections.abc import Iterable
|
||||
import fnmatch
|
||||
import importlib
|
||||
import inspect
|
||||
@@ -36,7 +36,7 @@ def _indent(text: str) -> str:
|
||||
"""Indent by four spaces."""
|
||||
prefix = ' ' * 4
|
||||
|
||||
def prefixed_lines() -> collections.abc.Iterable[str]:
|
||||
def prefixed_lines() -> Iterable[str]:
|
||||
for line in text.splitlines(True):
|
||||
yield (prefix + line if line.strip() else line)
|
||||
|
||||
@@ -45,7 +45,7 @@ def _indent(text: str) -> str:
|
||||
|
||||
def _format_description(
|
||||
parser: argparse.ArgumentParser,
|
||||
) -> collections.abc.Iterable[str]:
|
||||
) -> Iterable[str]:
|
||||
"""Get parser description.
|
||||
|
||||
We parse this as reStructuredText, allowing users to embed rich
|
||||
@@ -110,7 +110,7 @@ def _format_usage(parser: argparse.ArgumentParser) -> list[str]:
|
||||
|
||||
def _format_epilog(
|
||||
parser: argparse.ArgumentParser,
|
||||
) -> collections.abc.Iterable[str]:
|
||||
) -> Iterable[str]:
|
||||
"""Get parser epilog.
|
||||
|
||||
We parse this as reStructuredText, allowing users to embed rich
|
||||
@@ -127,7 +127,7 @@ def _format_epilog(
|
||||
|
||||
def _format_positional_action(
|
||||
action: argparse.Action,
|
||||
) -> collections.abc.Iterable[str]:
|
||||
) -> Iterable[str]:
|
||||
"""Format a positional action."""
|
||||
if action.help == argparse.SUPPRESS:
|
||||
return
|
||||
@@ -156,7 +156,7 @@ def _format_positional_action(
|
||||
|
||||
def _format_optional_action(
|
||||
action: argparse.Action,
|
||||
) -> collections.abc.Iterable[str]:
|
||||
) -> Iterable[str]:
|
||||
"""Format an optional action."""
|
||||
if action.help == argparse.SUPPRESS or action.option_strings is None:
|
||||
return
|
||||
@@ -191,7 +191,7 @@ def _format_optional_action(
|
||||
|
||||
def _format_parser(
|
||||
parser: argparse.ArgumentParser,
|
||||
) -> collections.abc.Iterable[str]:
|
||||
) -> Iterable[str]:
|
||||
"""Format the output of an argparse 'ArgumentParser' object.
|
||||
|
||||
Given the following parser::
|
||||
|
||||
Reference in New Issue
Block a user