Skip to content

Commit b290811

Browse files
woodruffwDarkaMaul
andauthored
Run mypy on tests (#43)
Co-authored-by: dm <[email protected]>
1 parent 70de5d4 commit b290811

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ lint: $(VENV)/pyvenv.cfg
5454
. $(VENV_BIN)/activate && \
5555
ruff format --check $(ALL_PY_SRCS) && \
5656
ruff check $(ALL_PY_SRCS) && \
57-
mypy
57+
mypy src/ test/
5858
. $(VENV_BIN)/activate && \
5959
interrogate -c pyproject.toml .
6060

pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ lint = [
3434
"types-requests",
3535
"types-toml",
3636
"interrogate",
37+
# linting relies on test deps, since we also typecheck our test suite
38+
"pypi-attestations[test]",
3739
]
38-
dev = ["pypi-attestations[doc,test,lint]", "twine", "wheel", "build"]
40+
dev = ["pypi-attestations[doc,test,lint]", "build"]
3941

4042

4143
[project.urls]
@@ -54,6 +56,7 @@ omit = ["src/pypi_attestations/_cli.py", "src/pypi_attestations/__main__.py"]
5456
[tool.mypy]
5557
mypy_path = "src"
5658
packages = "pypi_attestations"
59+
plugins = ["pydantic.mypy"]
5760
allow_redefinition = true
5861
check_untyped_defs = true
5962
disallow_incomplete_defs = true
@@ -88,6 +91,7 @@ ignore = ["ANN101", "ANN102", "D203", "D213", "COM812", "ISC001"]
8891
"D", # no docstrings in tests
8992
"S101", # asserts are expected in tests
9093
"SLF001", # private APIs are expected in tests
94+
"ANN401", # dynamic types are OK in tests
9195
]
9296

9397
[tool.interrogate]

test/test_impl.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
from hashlib import sha256
66
from pathlib import Path
7+
from typing import Any
78

89
import pretend
910
import pypi_attestations._impl as impl
@@ -75,7 +76,7 @@ def test_roundtrip(self, id_token: IdentityToken) -> None:
7576
def test_wrong_predicate_raises_exception(self, monkeypatch: pytest.MonkeyPatch) -> None:
7677
def dummy_predicate(self_: StatementBuilder, _: str) -> StatementBuilder:
7778
# wrong type here to have a validation error
78-
self_._predicate_type = False
79+
self_._predicate_type = False # type: ignore[assignment]
7980
return self_
8081

8182
monkeypatch.setattr(sigstore.dsse.StatementBuilder, "predicate_type", dummy_predicate)
@@ -100,7 +101,7 @@ def in_validity_period(_: IdentityToken) -> bool:
100101
def test_multiple_signatures(
101102
self, id_token: IdentityToken, monkeypatch: pytest.MonkeyPatch
102103
) -> None:
103-
def get_bundle(*_) -> Bundle: # noqa: ANN002
104+
def get_bundle(*_: Any) -> Bundle:
104105
# Duplicate the signature to trigger a Conversion error
105106
bundle = Bundle.from_json(gh_signed_dist_bundle_path.read_bytes())
106107
bundle._inner.dsse_envelope.signatures.append(bundle._inner.dsse_envelope.signatures[0])
@@ -468,15 +469,15 @@ def test_ultranormalize_dist_filename_invalid(input: str) -> None:
468469
class TestPublisher:
469470
def test_discriminator(self) -> None:
470471
gh_raw = {"kind": "GitHub", "repository": "foo/bar", "workflow": "publish.yml"}
471-
gh = TypeAdapter(impl.Publisher).validate_python(gh_raw)
472+
gh: impl.Publisher = TypeAdapter(impl.Publisher).validate_python(gh_raw)
472473

473474
assert isinstance(gh, impl.GitHubPublisher)
474475
assert gh.repository == "foo/bar"
475476
assert gh.workflow == "publish.yml"
476477
assert TypeAdapter(impl.Publisher).validate_json(json.dumps(gh_raw)) == gh
477478

478479
gl_raw = {"kind": "GitLab", "repository": "foo/bar/baz", "environment": "publish"}
479-
gl = TypeAdapter(impl.Publisher).validate_python(gl_raw)
480+
gl: impl.Publisher = TypeAdapter(impl.Publisher).validate_python(gl_raw)
480481
assert isinstance(gl, impl.GitLabPublisher)
481482
assert gl.repository == "foo/bar/baz"
482483
assert gl.environment == "publish"
@@ -499,7 +500,7 @@ def test_claims(self) -> None:
499500
"this-too": 123,
500501
},
501502
}
502-
pub = TypeAdapter(impl.Publisher).validate_python(raw)
503+
pub: impl.Publisher = TypeAdapter(impl.Publisher).validate_python(raw)
503504

504505
assert pub.claims == {
505506
"this": "is-preserved",

0 commit comments

Comments
 (0)