Commit c2d76264 authored by Laurent Peuch's avatar Laurent Peuch
Browse files

[ureports/fix] make all nodes importables from logilab.common.ureports

parent 26f8c06f6721
Pipeline #7810 passed with stages
in 2 minutes and 7 seconds
......@@ -24,13 +24,15 @@ __docformat__ = "restructuredtext en"
import sys
from typing import Any, Optional, Union, List, Generator, Tuple, Callable, TextIO
from typing import Any, Optional, Union, List as ListType, Generator, Tuple, Callable, TextIO
from logilab.common.compat import StringIO
from logilab.common.textutils import linesep
from logilab.common.tree import VNode
from logilab.common.ureports.nodes import Table, Section, Link, Paragraph, Title, Text
from logilab.common.ureports.nodes import VerbatimText, Image, Span, List # noqa
def get_nodes(node, klass):
"""return an iterator on all children node of the given klass"""
......@@ -54,7 +56,7 @@ def build_summary(layout, level=1):
"""make a summary for the report, including X level"""
assert level > 0
level -= 1
summary = List(klass="summary")
summary = ListType(klass="summary")
for child in layout.children:
if not isinstance(child, Section):
......@@ -97,7 +99,7 @@ class BaseWriter(object):
if not encoding:
encoding = getattr(stream, "encoding", "UTF-8")
self.encoding = encoding or "UTF-8"
self.__compute_funcs: List[Tuple[Callable[[str], Any], Callable[[str], Any]]] = []
self.__compute_funcs: ListType[Tuple[Callable[[str], Any], Callable[[str], Any]]] = []
self.out = stream
......@@ -130,12 +132,12 @@ class BaseWriter(object):
def end_format(self, layout: Any) -> None:
"""finished to format a layout"""
def get_table_content(self, table: Table) -> List[List[str]]:
def get_table_content(self, table: Table) -> ListType[ListType[str]]:
"""trick to get table content without actually writing it
return an aligned list of lists containing table cells values as string
result: List[List[str]] = [[]]
result: ListType[ListType[str]] = [[]]
# mypy: "Table" has no attribute "cols"
# dynamic attribute
cols = table.cols # type: ignore
......@@ -189,7 +191,7 @@ class BaseWriter(object):
self.__compute_funcs.append((write, writeln))
# mypy: Item "Table" of "Union[List[Any], Table, Title]" has no attribute "children"
# mypy: Item "Table" of "Union[ListType[Any], Table, Title]" has no attribute "children"
# dynamic attribute?
for child in layout.children: # type: ignore
stream = StringIO()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment