From 4fc3802d8f1455d5156ef5b185a70353752c461f Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Sat, 21 Aug 2021 22:27:41 +0200 Subject: Type fixes in templates.Template Since we switched to our internal document representation, the templates don't return the plain nodes anymore. --- wikimini/__init__.py | 6 +++--- wikimini/templates/__init__.py | 8 ++++++-- 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: -- cgit v1.2.3