summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2021-08-21 22:59:52 +0200
committerDaniel Schadt <kingdread@gmx.de>2021-08-21 22:59:52 +0200
commitf39ec7d2f4b609c0968767590eeb864a48b41401 (patch)
tree312956876d49206c8f22252cc5ac8a80385751b2
parentf384001e0818968306917566c2007c21a7a13613 (diff)
downloadwikimini-f39ec7d2f4b609c0968767590eeb864a48b41401.tar.gz
wikimini-f39ec7d2f4b609c0968767590eeb864a48b41401.tar.bz2
wikimini-f39ec7d2f4b609c0968767590eeb864a48b41401.zip
More type fixes
This makes mypy happier about how we use .extend, since it doesn't know about the fact that all list items should be either Node or Block, not mixed. In the first case, we can fix it by using .append(current[0]), as mypy will see the isinstance() above and ascribe the correct type. In the second case, we use the cast no-op function to assign the correct type. That should be cheap and makes mypy happy, even if it doesn't give us any runtime checks (which is fine, this is Python after all). In the third case, we're iterating over every element anyway, so we can throw in an assert to make sure the list item has the correct type. This also helps in catching some bugs, in case .convert() returns a mixed list (but only if the first item happens to be a Node).
-rw-r--r--wikimini/__init__.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/wikimini/__init__.py b/wikimini/__init__.py
index 6c2f2a6..f927a94 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, Sequence
+from typing import List, Union, Tuple, Sequence, Iterable, cast
from .document import (
Plain, BlockLink, InlineLink, Verbatim, Document, Node, Block, ItemList,
@@ -81,7 +81,7 @@ class Wikimini:
"prop": "revisions",
"rvprop": "content",
"rvslots": "main",
- "rvlimit": 1,
+ "rvlimit": "1",
"titles": title,
"format": "json",
"formatversion": "2",
@@ -142,12 +142,13 @@ class Wikimini:
pass
# Special case: We're starting a list!
elif len(current) == 1 and isinstance(current[0], ItemList):
- document.extend(current)
+ document.append(current[0])
elif isinstance(current[0], Block):
- document.extend(current)
+ document.extend(cast(Iterable[Block], current))
document.append(Paragraph([]))
elif isinstance(current[0], Node):
for c in current:
+ assert isinstance(c, Node)
insert_into(document, c)
return document
elif isinstance(obj, mwp.nodes.heading.Heading):