summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2021-08-21 22:27:41 +0200
committerDaniel Schadt <kingdread@gmx.de>2021-08-21 22:27:41 +0200
commit4fc3802d8f1455d5156ef5b185a70353752c461f (patch)
tree76064acdb9ab5d0ff93fedfa525c453bb8e0ee64
parent662fcdc06012efacad53125ee4a449b632fad187 (diff)
downloadwikimini-4fc3802d8f1455d5156ef5b185a70353752c461f.tar.gz
wikimini-4fc3802d8f1455d5156ef5b185a70353752c461f.tar.bz2
wikimini-4fc3802d8f1455d5156ef5b185a70353752c461f.zip
Type fixes in templates.Template
Since we switched to our internal document representation, the templates don't return the plain nodes anymore.
-rw-r--r--wikimini/__init__.py6
-rw-r--r--wikimini/templates/__init__.py8
2 files changed, 9 insertions, 5 deletions
diff --git a/wikimini/__init__.py b/wikimini/__init__.py
index 00179cc..3e344fd 100644
--- a/wikimini/__init__.py
+++ b/wikimini/__init__.py
@@ -5,7 +5,7 @@ import requests
from tabulate import tabulate
-from typing import List, Union, Tuple
+from typing import List, Union, Tuple, Sequence
from .document import (
Plain, BlockLink, InlineLink, Verbatim, Document, Node, Block, ItemList,
@@ -98,7 +98,7 @@ class Wikimini:
def convert(
self,
obj: Union[mwp.wikicode.Wikicode, mwp.nodes.Node],
- ) -> Union[Document, List[Node], List[Block]]:
+ ) -> Union[Document, Sequence[Node], Sequence[Block]]:
"""Function that converts and renders a node.
This function is exposed for template implementors, for normal usage,
@@ -127,7 +127,7 @@ class Wikimini:
[Plain(mwp.wikicode.Wikicode([obj]).strip_code(collapse=False))]
if isinstance(obj, mwp.wikicode.Wikicode):
- document = []
+ document: List[Block] = []
for node in obj.nodes:
current = self.convert(node)
diff --git a/wikimini/templates/__init__.py b/wikimini/templates/__init__.py
index ebe3bbc..533ba5e 100644
--- a/wikimini/templates/__init__.py
+++ b/wikimini/templates/__init__.py
@@ -7,15 +7,19 @@ and the :class:`~mwparserfromhell.nodes.template.Template` node to convert, and
returns a string with the template output (see :const:`Template`).
"""
import copy
-from typing import Callable, Optional
+from typing import Callable, Optional, Union, Sequence
import mwparserfromhell as mwp
from .. import Wikimini
+from ..document import Block, Node
#: The type of a template render function.
-Template = Callable[[Wikimini, mwp.nodes.template.Template], str]
+Template = Callable[
+ [Wikimini, mwp.nodes.template.Template],
+ Union[Sequence[Block], Sequence[Node]]
+]
class Registry: