mirror of https://github.com/Textualize/rich.git
typing fix
This commit is contained in:
parent
0d758dbf1e
commit
bee681d359
|
@ -25,14 +25,3 @@ def divide_line(text: str, width: int) -> List[int]:
|
|||
line_size = 0
|
||||
line_size += len(word)
|
||||
return divides
|
||||
|
||||
|
||||
if __name__ == "__main__": # pragma: no cover
|
||||
test = " Where there is a Will there is a way. Hello World. There can be only one."
|
||||
|
||||
boundaries = [0, *wrap(test, 10), len(test)]
|
||||
print(boundaries)
|
||||
for start, end in zip(boundaries, boundaries[1:]):
|
||||
line = test[start:end]
|
||||
print(f"{len(line)}\t", repr(line))
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from dataclasses import dataclass
|
||||
from typing import Any, ClassVar, Dict, Iterable, List, Optional, Union
|
||||
from typing import Any, ClassVar, Dict, Iterable, List, Optional, Type, Union
|
||||
|
||||
from commonmark.blocks import Parser
|
||||
|
||||
|
@ -162,7 +162,7 @@ class CodeBlock(TextElement):
|
|||
style_name = "markdown.code_block"
|
||||
|
||||
@classmethod
|
||||
def create(cls, markdown: "Markdown", node: Any) -> "ListElement":
|
||||
def create(cls, markdown: "Markdown", node: Any) -> "CodeBlock":
|
||||
if node.info is None:
|
||||
return cls("default", markdown.code_theme)
|
||||
lexer_name, _, _ = node.info.partition(" ")
|
||||
|
@ -333,7 +333,7 @@ class MarkdownContext:
|
|||
|
||||
class Markdown:
|
||||
|
||||
elements: ClassVar[Dict[str, MarkdownElement]] = {
|
||||
elements: ClassVar[Dict[str, Type[MarkdownElement]]] = {
|
||||
"paragraph": Paragraph,
|
||||
"heading": Heading,
|
||||
"code_block": CodeBlock,
|
||||
|
|
|
@ -33,17 +33,6 @@ from ._render_width import RenderWidth
|
|||
from ._tools import iter_first_last, iter_first, iter_last, ratio_divide
|
||||
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
|
||||
def _pick_first(values: Iterable[Optional[T]], final: T) -> T:
|
||||
"""Pick first non-None value."""
|
||||
for value in values:
|
||||
if value is not None:
|
||||
return value
|
||||
return final
|
||||
|
||||
|
||||
@dataclass
|
||||
class Column:
|
||||
"""Defines a column in a table."""
|
||||
|
@ -167,12 +156,26 @@ class Table:
|
|||
width (int, optional): A minimum width in characters. Defaults to None.
|
||||
ratio (int, optional): Flexible ratio for the column. Defaults to None.
|
||||
"""
|
||||
|
||||
def _pick_first_style(
|
||||
*values: Optional[Union[Style, str]]
|
||||
) -> Union[Style, str]:
|
||||
"""Pick first non-None style."""
|
||||
for value in values:
|
||||
if value is not None:
|
||||
return value
|
||||
raise ValueError("expected at least one non-None style")
|
||||
|
||||
column = Column(
|
||||
header=header,
|
||||
footer=footer,
|
||||
header_style=_pick_first((header_style, self.header_style), "table.header"),
|
||||
footer_style=_pick_first((footer_style, self.footer_style), "table.footer"),
|
||||
style=_pick_first((style, self.style), "table.cell"),
|
||||
header_style=_pick_first_style(
|
||||
header_style, self.header_style, "table.header"
|
||||
),
|
||||
footer_style=_pick_first_style(
|
||||
footer_style, self.footer_style, "table.footer"
|
||||
),
|
||||
style=_pick_first_style(style, self.style, "table.cell"),
|
||||
justify=justify,
|
||||
width=width,
|
||||
ratio=ratio,
|
||||
|
|
|
@ -366,7 +366,7 @@ class Text:
|
|||
else:
|
||||
raise TypeError("Only str or Text can be appended to Text")
|
||||
|
||||
def split(self, separator="\n", include_separator: bool = False) -> List["Text"]:
|
||||
def split(self, separator="\n", include_separator: bool = False) -> Lines:
|
||||
"""Split rich text in to lines, preserving styles.
|
||||
|
||||
Args:
|
||||
|
@ -379,7 +379,7 @@ class Text:
|
|||
|
||||
text = self.text
|
||||
if separator not in text:
|
||||
return [self.copy()]
|
||||
return Lines([self.copy()])
|
||||
if text.endswith(separator):
|
||||
text = text[: -len(separator)]
|
||||
offsets: List[int] = []
|
||||
|
|
Loading…
Reference in New Issue