diff --git a/src/pytest_html/extras.py b/src/pytest_html/extras.py index 84fc2837..abf7e4c8 100644 --- a/src/pytest_html/extras.py +++ b/src/pytest_html/extras.py @@ -1,7 +1,8 @@ # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -# type: ignore +from typing import Dict +from typing import Optional FORMAT_HTML = "html" FORMAT_IMAGE = "image" @@ -11,7 +12,13 @@ FORMAT_VIDEO = "video" -def extra(content, format_type, name=None, mime_type=None, extension=None): +def extra( + content: str, + format_type: str, + name: Optional[str] = None, + mime_type: Optional[str] = None, + extension: Optional[str] = None, +) -> Dict[str, Optional[str]]: return { "name": name, "format_type": format_type, @@ -21,41 +28,51 @@ def extra(content, format_type, name=None, mime_type=None, extension=None): } -def html(content): +def html(content: str) -> Dict[str, Optional[str]]: return extra(content, FORMAT_HTML) -def image(content, name="Image", mime_type="image/png", extension="png"): +def image( + content: str, + name: str = "Image", + mime_type: str = "image/png", + extension: str = "png", +) -> Dict[str, Optional[str]]: return extra(content, FORMAT_IMAGE, name, mime_type, extension) -def png(content, name="Image"): +def png(content: str, name: str = "Image") -> Dict[str, Optional[str]]: return image(content, name, mime_type="image/png", extension="png") -def jpg(content, name="Image"): +def jpg(content: str, name: str = "Image") -> Dict[str, Optional[str]]: return image(content, name, mime_type="image/jpeg", extension="jpg") -def svg(content, name="Image"): +def svg(content: str, name: str = "Image") -> Dict[str, Optional[str]]: return image(content, name, mime_type="image/svg+xml", extension="svg") -def json(content, name="JSON"): +def json(content: str, name: str = "JSON") -> Dict[str, Optional[str]]: return extra(content, FORMAT_JSON, name, "application/json", "json") -def text(content, name="Text"): +def text(content: str, name: str = "Text") -> Dict[str, Optional[str]]: return extra(content, FORMAT_TEXT, name, "text/plain", "txt") -def url(content, name="URL"): +def url(content: str, name: str = "URL") -> Dict[str, Optional[str]]: return extra(content, FORMAT_URL, name) -def video(content, name="Video", mime_type="video/mp4", extension="mp4"): +def video( + content: str, + name: str = "Video", + mime_type: str = "video/mp4", + extension: str = "mp4", +) -> Dict[str, Optional[str]]: return extra(content, FORMAT_VIDEO, name, mime_type, extension) -def mp4(content, name="Video"): +def mp4(content: str, name: str = "Video") -> Dict[str, Optional[str]]: return video(content, name)