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 <pierre.sassoulas@gmail.com>
This commit is contained in:
Gleb Nikonorov 2024-11-20 10:22:46 -05:00 committed by GitHub
parent 9aa1b99853
commit c2181e4e83
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 55 additions and 13 deletions

View File

@ -53,7 +53,13 @@ repos:
- eslint@8.20.0 - eslint@8.20.0
- eslint-config-google@0.14.0 - eslint-config-google@0.14.0
args: ["--fix"] args: ["--fix"]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.13.0
hooks:
- id: mypy
files: ^(src/pytest_html|testing)
additional_dependencies:
- types-setuptools
- repo: local - repo: local
hooks: hooks:
- id: rst - id: rst

View File

@ -98,3 +98,20 @@ version-file = "src/pytest_html/__version.py"
[tool.hatch.build.hooks.custom] [tool.hatch.build.hooks.custom]
path = "scripts/npm.py" path = "scripts/npm.py"
[tool.mypy]
check_untyped_defs = false # TODO
disallow_any_generics = true
disallow_incomplete_defs = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = false # TODO
ignore_missing_imports = true
no_implicit_optional = true
no_implicit_reexport = true
show_error_codes = true
strict_equality = true
warn_redundant_casts = true
warn_return_any = true
warn_unreachable = true
warn_unused_configs = true

View File

@ -1,5 +1,5 @@
try: try:
from . import __version from . import __version # type: ignore
__version__ = __version.version __version__ = __version.version
except ImportError: except ImportError:

View File

@ -1,6 +1,8 @@
# This Source Code Form is subject to the terms of the Mozilla Public # 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 # 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/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
from typing import Dict
from typing import Optional
FORMAT_HTML = "html" FORMAT_HTML = "html"
FORMAT_IMAGE = "image" FORMAT_IMAGE = "image"
@ -10,7 +12,13 @@ FORMAT_URL = "url"
FORMAT_VIDEO = "video" 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 { return {
"name": name, "name": name,
"format_type": format_type, "format_type": format_type,
@ -20,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) 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) 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") 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") 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") 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") 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") 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) 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) 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) return video(content, name)

View File

@ -1,6 +1,7 @@
# This Source Code Form is subject to the terms of the Mozilla Public # 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 # 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/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
# type: ignore
import json import json
import os import os
import random import random