From 3fd0b39b5174e24c86c6b660ef36d3075b1eb68a Mon Sep 17 00:00:00 2001 From: Taneli Hukkinen Date: Thu, 7 Jan 2021 01:53:27 +0200 Subject: [PATCH 1/2] Make `NestedTokens.closing` not optional --- markdown_it/token.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/markdown_it/token.py b/markdown_it/token.py index 98b7e882..ed6b25ac 100644 --- a/markdown_it/token.py +++ b/markdown_it/token.py @@ -117,7 +117,7 @@ class NestedTokens: """ opening: Token = attr.ib() - closing: Optional[Token] = attr.ib() + closing: Token = attr.ib() children: List[Union[Token, "NestedTokens"]] = attr.ib(factory=list) def __getattr__(self, name): From 64527c8a3290892082f9fd2c0be0add81b6ba2a3 Mon Sep 17 00:00:00 2001 From: Taneli Hukkinen Date: Thu, 7 Jan 2021 03:14:31 +0200 Subject: [PATCH 2/2] Explain "type: ignore" --- markdown_it/token.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/markdown_it/token.py b/markdown_it/token.py index ed6b25ac..d0bfa400 100644 --- a/markdown_it/token.py +++ b/markdown_it/token.py @@ -144,6 +144,9 @@ def nest_tokens(tokens: List[Token]) -> List[Union[Token, NestedTokens]]: token = token.copy() output.append(token) if token.children: + # Ignore type checkers because `nest_tokens` doesn't respect + # typing of `Token.children`. We add `NestedTokens` into a + # `List[Token]` here. token.children = nest_tokens(token.children) # type: ignore continue