aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/prompt-toolkit/py3/prompt_toolkit/layout/utils.py
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.ru>2022-02-10 16:44:39 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:44:39 +0300
commite9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (patch)
tree64175d5cadab313b3e7039ebaa06c5bc3295e274 /contrib/python/prompt-toolkit/py3/prompt_toolkit/layout/utils.py
parent2598ef1d0aee359b4b6d5fdd1758916d5907d04f (diff)
downloadydb-e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0.tar.gz
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/python/prompt-toolkit/py3/prompt_toolkit/layout/utils.py')
-rw-r--r--contrib/python/prompt-toolkit/py3/prompt_toolkit/layout/utils.py158
1 files changed, 79 insertions, 79 deletions
diff --git a/contrib/python/prompt-toolkit/py3/prompt_toolkit/layout/utils.py b/contrib/python/prompt-toolkit/py3/prompt_toolkit/layout/utils.py
index 6d9eb196c8..2e0f34388b 100644
--- a/contrib/python/prompt-toolkit/py3/prompt_toolkit/layout/utils.py
+++ b/contrib/python/prompt-toolkit/py3/prompt_toolkit/layout/utils.py
@@ -1,80 +1,80 @@
-from typing import TYPE_CHECKING, Iterable, List, TypeVar, Union, cast, overload
-
-from prompt_toolkit.formatted_text.base import OneStyleAndTextTuple
-
-if TYPE_CHECKING:
- from typing_extensions import SupportsIndex
-
-__all__ = [
- "explode_text_fragments",
-]
-
-_T = TypeVar("_T", bound=OneStyleAndTextTuple)
-
-
-class _ExplodedList(List[_T]):
- """
- Wrapper around a list, that marks it as 'exploded'.
-
- As soon as items are added or the list is extended, the new items are
- automatically exploded as well.
- """
-
- exploded = True
-
- def append(self, item: _T) -> None:
- self.extend([item])
-
- def extend(self, lst: Iterable[_T]) -> None:
- super().extend(explode_text_fragments(lst))
-
+from typing import TYPE_CHECKING, Iterable, List, TypeVar, Union, cast, overload
+
+from prompt_toolkit.formatted_text.base import OneStyleAndTextTuple
+
+if TYPE_CHECKING:
+ from typing_extensions import SupportsIndex
+
+__all__ = [
+ "explode_text_fragments",
+]
+
+_T = TypeVar("_T", bound=OneStyleAndTextTuple)
+
+
+class _ExplodedList(List[_T]):
+ """
+ Wrapper around a list, that marks it as 'exploded'.
+
+ As soon as items are added or the list is extended, the new items are
+ automatically exploded as well.
+ """
+
+ exploded = True
+
+ def append(self, item: _T) -> None:
+ self.extend([item])
+
+ def extend(self, lst: Iterable[_T]) -> None:
+ super().extend(explode_text_fragments(lst))
+
def insert(self, index: "SupportsIndex", item: _T) -> None:
- raise NotImplementedError # TODO
-
- # TODO: When creating a copy() or [:], return also an _ExplodedList.
-
- @overload
- def __setitem__(self, index: "SupportsIndex", value: _T) -> None:
- ...
-
- @overload
- def __setitem__(self, index: slice, value: Iterable[_T]) -> None:
- ...
-
- def __setitem__(
- self, index: Union["SupportsIndex", slice], value: Union[_T, Iterable[_T]]
- ) -> None:
- """
- Ensure that when `(style_str, 'long string')` is set, the string will be
- exploded.
- """
- if not isinstance(index, slice):
- int_index = index.__index__()
- index = slice(int_index, int_index + 1)
- if isinstance(value, tuple): # In case of `OneStyleAndTextTuple`.
- value = cast("List[_T]", [value])
-
- super().__setitem__(index, explode_text_fragments(cast("Iterable[_T]", value)))
-
-
-def explode_text_fragments(fragments: Iterable[_T]) -> _ExplodedList[_T]:
- """
- Turn a list of (style_str, text) tuples into another list where each string is
- exactly one character.
-
- It should be fine to call this function several times. Calling this on a
- list that is already exploded, is a null operation.
-
- :param fragments: List of (style, text) tuples.
- """
- # When the fragments is already exploded, don't explode again.
- if isinstance(fragments, _ExplodedList):
- return fragments
-
- result: List[_T] = []
-
- for style, string, *rest in fragments: # type: ignore
- for c in string: # type: ignore
- result.append((style, c, *rest)) # type: ignore
-
- return _ExplodedList(result)
+ raise NotImplementedError # TODO
+
+ # TODO: When creating a copy() or [:], return also an _ExplodedList.
+
+ @overload
+ def __setitem__(self, index: "SupportsIndex", value: _T) -> None:
+ ...
+
+ @overload
+ def __setitem__(self, index: slice, value: Iterable[_T]) -> None:
+ ...
+
+ def __setitem__(
+ self, index: Union["SupportsIndex", slice], value: Union[_T, Iterable[_T]]
+ ) -> None:
+ """
+ Ensure that when `(style_str, 'long string')` is set, the string will be
+ exploded.
+ """
+ if not isinstance(index, slice):
+ int_index = index.__index__()
+ index = slice(int_index, int_index + 1)
+ if isinstance(value, tuple): # In case of `OneStyleAndTextTuple`.
+ value = cast("List[_T]", [value])
+
+ super().__setitem__(index, explode_text_fragments(cast("Iterable[_T]", value)))
+
+
+def explode_text_fragments(fragments: Iterable[_T]) -> _ExplodedList[_T]:
+ """
+ Turn a list of (style_str, text) tuples into another list where each string is
+ exactly one character.
+
+ It should be fine to call this function several times. Calling this on a
+ list that is already exploded, is a null operation.
+
+ :param fragments: List of (style, text) tuples.
+ """
+ # When the fragments is already exploded, don't explode again.
+ if isinstance(fragments, _ExplodedList):
+ return fragments
+
+ result: List[_T] = []
+
+ for style, string, *rest in fragments: # type: ignore
+ for c in string: # type: ignore
+ result.append((style, c, *rest)) # type: ignore
+
+ return _ExplodedList(result)