Skip to content

Commit

Permalink
Set no_implicit_optional=True mypy conf
Browse files Browse the repository at this point in the history
  • Loading branch information
hukkinj1 committed Oct 31, 2020
1 parent f39a610 commit 3369007
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 11 deletions.
1 change: 1 addition & 0 deletions .mypy.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[mypy]
warn_unused_ignores = True
warn_redundant_casts = True
no_implicit_optional = True
4 changes: 2 additions & 2 deletions markdown_it/common/normalize_url.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import html
import re
from typing import Callable
from typing import Callable, Optional
from urllib.parse import urlparse, urlunparse, quote, unquote # noqa: F401

from .utils import ESCAPABLE
Expand Down Expand Up @@ -166,7 +166,7 @@ def normalizeLinkText(link):
GOOD_DATA_RE = re.compile(r"^data:image\/(gif|png|jpeg|webp);")


def validateLink(url: str, validator: Callable = None):
def validateLink(url: str, validator: Optional[Callable] = None):
"""Validate URL link is allowed in output.
This validator can prohibit more than really needed to prevent XSS.
Expand Down
4 changes: 2 additions & 2 deletions markdown_it/extensions/container/index.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Process block-level custom containers."""
from math import floor
from typing import Callable
from typing import Callable, Optional

from markdown_it import MarkdownIt
from markdown_it.common.utils import charCodeAt
Expand All @@ -11,7 +11,7 @@ def container_plugin(
md: MarkdownIt,
name: str,
marker: str = ":",
validate: Callable[[str, str], bool] = None,
validate: Optional[Callable[[str, str], bool]] = None,
render=None,
):
"""Plugin ported from
Expand Down
11 changes: 9 additions & 2 deletions markdown_it/parser_block.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Block-level tokenizer."""
import logging
from typing import List
from typing import List, Optional

from .ruler import Ruler
from .token import Token
Expand Down Expand Up @@ -92,7 +92,14 @@ def tokenize(
line += 1
state.line = line

def parse(self, src: str, md, env, outTokens: List[Token], ords: List[int] = None):
def parse(
self,
src: str,
md,
env,
outTokens: List[Token],
ords: Optional[List[int]] = None,
):
"""Process input string and push block tokens into `outTokens`."""
if not src:
return
Expand Down
9 changes: 7 additions & 2 deletions markdown_it/rules_block/state_block.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List
from typing import List, Optional

from ..token import Token
from ..ruler import StateBase
Expand All @@ -7,7 +7,12 @@

class StateBlock(StateBase):
def __init__(
self, src: str, md, env, tokens: List[Token], srcCharCode: List[int] = None
self,
src: str,
md,
env,
tokens: List[Token],
srcCharCode: Optional[List[int]] = None,
):

self.src = src
Expand Down
6 changes: 3 additions & 3 deletions markdown_it/rules_core/smartquotes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Convert straight quotation marks to typographic ones
"""
import re
from typing import List
from typing import Any, Dict, List

from .state_core import StateCore
from ..common.utils import charCodeAt
Expand All @@ -22,7 +22,7 @@ def replaceAt(string: str, index: int, ch: str):


def process_inlines(tokens: List[Token], state: StateCore):
stack = []
stack: List[Dict[str, Any]] = []

for i in range(len(tokens)):
token = tokens[i]
Expand Down Expand Up @@ -202,5 +202,5 @@ def smartquotes(state: StateCore):

if token.type != "inline" or not QUOTE_RE.search(token.content):
continue

assert token.children is not None
process_inlines(token.children, state)

0 comments on commit 3369007

Please sign in to comment.