Skip to content

Commit dd258ea

Browse files
committed
type extras.py
1 parent cbfcf61 commit dd258ea

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

src/pytest_html/extras.py

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# This Source Code Form is subject to the terms of the Mozilla Public
22
# License, v. 2.0. If a copy of the MPL was not distributed with this
33
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4-
# type: ignore
4+
from typing import Dict
5+
from typing import Optional
56

67
FORMAT_HTML = "html"
78
FORMAT_IMAGE = "image"
@@ -11,7 +12,13 @@
1112
FORMAT_VIDEO = "video"
1213

1314

14-
def extra(content, format_type, name=None, mime_type=None, extension=None):
15+
def extra(
16+
content: str,
17+
format_type: str,
18+
name: Optional[str] = None,
19+
mime_type: Optional[str] = None,
20+
extension: Optional[str] = None,
21+
) -> Dict[str, Optional[str]]:
1522
return {
1623
"name": name,
1724
"format_type": format_type,
@@ -21,41 +28,51 @@ def extra(content, format_type, name=None, mime_type=None, extension=None):
2128
}
2229

2330

24-
def html(content):
31+
def html(content: str) -> Dict[str, Optional[str]]:
2532
return extra(content, FORMAT_HTML)
2633

2734

28-
def image(content, name="Image", mime_type="image/png", extension="png"):
35+
def image(
36+
content: str,
37+
name: str = "Image",
38+
mime_type: str = "image/png",
39+
extension: str = "png",
40+
) -> Dict[str, Optional[str]]:
2941
return extra(content, FORMAT_IMAGE, name, mime_type, extension)
3042

3143

32-
def png(content, name="Image"):
44+
def png(content: str, name: str = "Image") -> Dict[str, Optional[str]]:
3345
return image(content, name, mime_type="image/png", extension="png")
3446

3547

36-
def jpg(content, name="Image"):
48+
def jpg(content: str, name: str = "Image") -> Dict[str, Optional[str]]:
3749
return image(content, name, mime_type="image/jpeg", extension="jpg")
3850

3951

40-
def svg(content, name="Image"):
52+
def svg(content: str, name: str = "Image") -> Dict[str, Optional[str]]:
4153
return image(content, name, mime_type="image/svg+xml", extension="svg")
4254

4355

44-
def json(content, name="JSON"):
56+
def json(content: str, name: str = "JSON") -> Dict[str, Optional[str]]:
4557
return extra(content, FORMAT_JSON, name, "application/json", "json")
4658

4759

48-
def text(content, name="Text"):
60+
def text(content: str, name: str = "Text") -> Dict[str, Optional[str]]:
4961
return extra(content, FORMAT_TEXT, name, "text/plain", "txt")
5062

5163

52-
def url(content, name="URL"):
64+
def url(content: str, name: str = "URL") -> Dict[str, Optional[str]]:
5365
return extra(content, FORMAT_URL, name)
5466

5567

56-
def video(content, name="Video", mime_type="video/mp4", extension="mp4"):
68+
def video(
69+
content: str,
70+
name: str = "Video",
71+
mime_type: str = "video/mp4",
72+
extension: str = "mp4",
73+
) -> Dict[str, Optional[str]]:
5774
return extra(content, FORMAT_VIDEO, name, mime_type, extension)
5875

5976

60-
def mp4(content, name="Video"):
77+
def mp4(content: str, name: str = "Video") -> Dict[str, Optional[str]]:
6178
return video(content, name)

0 commit comments

Comments
 (0)