Skip to content

Commit c2181e4

Browse files
Add mypy to CI pipeline and begin typing modules (#435)
* Add mypy to CI pipeline and begin typing effort * Make some hard options false to begin with something Co-authored-by: Pierre Sassoulas <[email protected]>
1 parent 9aa1b99 commit c2181e4

File tree

5 files changed

+55
-13
lines changed

5 files changed

+55
-13
lines changed

.pre-commit-config.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,13 @@ repos:
5353
5454
5555
args: ["--fix"]
56-
56+
- repo: https://github.com/pre-commit/mirrors-mypy
57+
rev: v1.13.0
58+
hooks:
59+
- id: mypy
60+
files: ^(src/pytest_html|testing)
61+
additional_dependencies:
62+
- types-setuptools
5763
- repo: local
5864
hooks:
5965
- id: rst

pyproject.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,20 @@ version-file = "src/pytest_html/__version.py"
9898

9999
[tool.hatch.build.hooks.custom]
100100
path = "scripts/npm.py"
101+
102+
[tool.mypy]
103+
check_untyped_defs = false # TODO
104+
disallow_any_generics = true
105+
disallow_incomplete_defs = true
106+
disallow_untyped_calls = true
107+
disallow_untyped_decorators = true
108+
disallow_untyped_defs = false # TODO
109+
ignore_missing_imports = true
110+
no_implicit_optional = true
111+
no_implicit_reexport = true
112+
show_error_codes = true
113+
strict_equality = true
114+
warn_redundant_casts = true
115+
warn_return_any = true
116+
warn_unreachable = true
117+
warn_unused_configs = true

src/pytest_html/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
try:
2-
from . import __version
2+
from . import __version # type: ignore
33

44
__version__ = __version.version
55
except ImportError:

src/pytest_html/extras.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +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+
from typing import Dict
5+
from typing import Optional
46

57
FORMAT_HTML = "html"
68
FORMAT_IMAGE = "image"
@@ -10,7 +12,13 @@
1012
FORMAT_VIDEO = "video"
1113

1214

13-
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]]:
1422
return {
1523
"name": name,
1624
"format_type": format_type,
@@ -20,41 +28,51 @@ def extra(content, format_type, name=None, mime_type=None, extension=None):
2028
}
2129

2230

23-
def html(content):
31+
def html(content: str) -> Dict[str, Optional[str]]:
2432
return extra(content, FORMAT_HTML)
2533

2634

27-
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]]:
2841
return extra(content, FORMAT_IMAGE, name, mime_type, extension)
2942

3043

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

3447

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

3851

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

4255

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

4659

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

5063

51-
def url(content, name="URL"):
64+
def url(content: str, name: str = "URL") -> Dict[str, Optional[str]]:
5265
return extra(content, FORMAT_URL, name)
5366

5467

55-
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]]:
5674
return extra(content, FORMAT_VIDEO, name, mime_type, extension)
5775

5876

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

testing/legacy_test_pytest_html.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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
45
import json
56
import os
67
import random

0 commit comments

Comments
 (0)