Skip to content

Commit

Permalink
lint: replace typing imports with relative ones
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Fiedler <miketheman@gmail.com>
  • Loading branch information
miketheman committed Mar 11, 2022
1 parent 4be323a commit 710c2e7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
14 changes: 7 additions & 7 deletions readme_renderer/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from __future__ import absolute_import, division, print_function

import functools
import typing
from typing import Any, Dict, Iterator, List, Optional

import bleach
import bleach.callbacks
Expand Down Expand Up @@ -64,10 +64,10 @@
class DisabledCheckboxInputsFilter:
# The typeshed for bleach (html5lib) filters is incomplete, use `typing.Any`
# See https://github.com/python/typeshed/blob/505ea726415016e53638c8b584b8fdc9c722cac1/stubs/bleach/bleach/html5lib_shim.pyi#L7-L8 # noqa E501
def __init__(self, source: typing.Any) -> None:
def __init__(self, source: Any) -> None:
self.source = source

def __iter__(self) -> typing.Iterator[typing.Dict[str, typing.Optional[str]]]:
def __iter__(self) -> Iterator[Dict[str, Optional[str]]]:
for token in self.source:
if token.get("name") == "input":
# only allow disabled checkbox inputs
Expand All @@ -85,15 +85,15 @@ def __iter__(self) -> typing.Iterator[typing.Dict[str, typing.Optional[str]]]:
else:
yield token

def __getattr__(self, name: str) -> typing.Any:
def __getattr__(self, name: str) -> Any:
return getattr(self.source, name)


def clean(
html: str,
tags: typing.Optional[typing.List[str]] = None,
attributes: typing.Optional[typing.Dict[str, typing.List[str]]] = None
) -> typing.Optional[str]:
tags: Optional[List[str]] = None,
attributes: Optional[Dict[str, List[str]]] = None
) -> Optional[str]:
if tags is None:
tags = ALLOWED_TAGS
if attributes is None:
Expand Down
8 changes: 4 additions & 4 deletions readme_renderer/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
from __future__ import absolute_import, division, print_function

import re
import typing
import warnings
from typing import Any, Match, Optional

from html import unescape

Expand Down Expand Up @@ -55,8 +55,8 @@
def render(
raw: str,
variant: str = "GFM",
**kwargs: typing.Any
) -> typing.Optional[str]:
**kwargs: Any
) -> Optional[str]:
if not variants:
warnings.warn(_EXTRA_WARNING)
return None
Expand Down Expand Up @@ -100,7 +100,7 @@ def _highlight(html: str) -> str:
'(?(in_code)|<code>)(?P<code>.+?)'
r'</code></pre>', re.DOTALL)

def replacer(match: typing.Match[typing.Any]) -> str:
def replacer(match: Match[Any]) -> str:
try:
lang = match.group('lang')
lang = _LANG_ALIASES.get(lang, lang)
Expand Down
16 changes: 8 additions & 8 deletions readme_renderer/rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from __future__ import absolute_import, division, print_function

import io
import typing
from typing import Any, Dict, IO, Optional, Union

from docutils.core import publish_parts
from docutils.nodes import colspec, image
Expand All @@ -27,15 +27,15 @@
class ReadMeHTMLTranslator(HTMLTranslator): # type: ignore[misc] # docutils is incomplete, returns `Any` python/typeshed#7256 # noqa E501

# Overrides base class not to output `<object>` tag for SVG images.
object_image_types = {} # type: ignore[var-annotated] # intentnionally empty
object_image_types: Dict[str, str] = {}

def emptytag(
self,
node: typing.Union[colspec, image],
node: Union[colspec, image],
tagname: str,
suffix: str = "\n",
**attributes: typing.Any
) -> typing.Any:
**attributes: Any
) -> Any:
"""Override this to add back the width/height attributes."""
if tagname == "img":
if "width" in node:
Expand Down Expand Up @@ -105,9 +105,9 @@ def emptytag(

def render(
raw: str,
stream: typing.Optional[typing.IO[str]] = None,
**kwargs: typing.Any
) -> typing.Optional[str]:
stream: Optional[IO[str]] = None,
**kwargs: Any
) -> Optional[str]:
if stream is None:
# Use a io.StringIO as the warning stream to prevent warnings from
# being printed to sys.stderr.
Expand Down
4 changes: 2 additions & 2 deletions readme_renderer/txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from __future__ import absolute_import, division, print_function

import sys
import typing
from typing import Any, Optional

from .clean import clean

Expand All @@ -27,6 +27,6 @@ def html_escape(s):
return escape(s, quote=True).replace("'", '&#x27;')


def render(raw: str, **kwargs: typing.Any) -> typing.Optional[str]:
def render(raw: str, **kwargs: Any) -> Optional[str]:
rendered = html_escape(raw).replace("\n", "<br>")
return clean(rendered, tags=["br"])

0 comments on commit 710c2e7

Please sign in to comment.