Skip to content

Commit d4d80ce

Browse files
committed
chore: add types to rst module
The types-docutils hints are still incomplete, good progress is being made. See: python/typeshed#7256 I've had to use an ignore on the class inheritance, and a couple of `typing.Any` annotations until that package implements more type hints. Signed-off-by: Mike Fiedler <miketheman@gmail.com>
1 parent c959bfd commit d4d80ce

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

readme_renderer/rst.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,28 @@
1414
from __future__ import absolute_import, division, print_function
1515

1616
import io
17+
import typing
1718

1819
from docutils.core import publish_parts
20+
from docutils.nodes import colspec, image
1921
from docutils.writers.html4css1 import HTMLTranslator, Writer
2022
from docutils.utils import SystemMessage
2123

2224
from .clean import clean
2325

2426

25-
class ReadMeHTMLTranslator(HTMLTranslator):
27+
class ReadMeHTMLTranslator(HTMLTranslator): # type: ignore
2628

2729
# Overrides base class not to output `<object>` tag for SVG images.
2830
object_image_types = {} # type: ignore
2931

30-
def emptytag(self, node, tagname, suffix="\n", **attributes):
32+
def emptytag(
33+
self,
34+
node: typing.Union[colspec, image],
35+
tagname: str,
36+
suffix: str = "\n",
37+
**attributes: typing.Any
38+
) -> typing.Any:
3139
"""Override this to add back the width/height attributes."""
3240
if tagname == "img":
3341
if "width" in node:
@@ -95,7 +103,11 @@ def emptytag(self, node, tagname, suffix="\n", **attributes):
95103
}
96104

97105

98-
def render(raw, stream=None, **kwargs):
106+
def render(
107+
raw: str,
108+
stream: typing.Optional[typing.Any] = None,
109+
**kwargs: typing.Any
110+
) -> typing.Optional[str]:
99111
if stream is None:
100112
# Use a io.StringIO as the warning stream to prevent warnings from
101113
# being printed to sys.stderr.

0 commit comments

Comments
 (0)