Skip to content

Commit 0b6e018

Browse files
authored
Merge pull request #970 from jku/annotate-hash
Annotate the library (add py.typed)
2 parents 1e1d674 + d17acca commit 0b6e018

File tree

9 files changed

+52
-47
lines changed

9 files changed

+52
-47
lines changed

.github/workflows/_test.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
include:
1717
# Run macOS tests on 3.9 (current OS X python) and latest,
1818
# Run Windows and "special" tests on latest Python version only
19+
# Run linter on oldest supported Python
1920
- python-version: "3.9"
2021
os: macos-latest
2122
toxenv: py
@@ -34,7 +35,7 @@ jobs:
3435
- python-version: "3.13"
3536
os: ubuntu-latest
3637
toxenv: py-test-gpg-fails
37-
- python-version: "3.13"
38+
- python-version: "3.9"
3839
os: ubuntu-latest
3940
toxenv: lint
4041

mypy.ini

-37
This file was deleted.

pyproject.toml

+40-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ include = [
6262
"/securesystemslib",
6363
"/requirements*.txt",
6464
"/tox.ini",
65-
"/mypy.ini",
6665
"/CHANGELOG.md",
6766
"/.coveragerc",
6867
]
@@ -87,4 +86,43 @@ indent-width = 4
8786
"tests/*" = [
8887
"S", # bandit: Not running bandit on tests
8988
"E501" # line-too-long
90-
]
89+
]
90+
91+
[tool.mypy]
92+
warn_unused_configs = "True"
93+
warn_redundant_casts = "True"
94+
warn_unused_ignores = "True"
95+
warn_unreachable = "True"
96+
strict_equality = "True"
97+
disallow_untyped_defs = "True"
98+
show_error_codes = "True"
99+
100+
exclude = [
101+
"^securesystemslib/_vendor/",
102+
"^securesystemslib/_gpg/",
103+
"^securesystemslib/hash.py",
104+
]
105+
106+
[[tool.mypy.overrides]]
107+
module = [
108+
# let's not install typeshed annotations for GCPSigner
109+
"google.*",
110+
# Suppress error messages for non-annotating dependencies
111+
"PyKCS11.*",
112+
"asn1crypto.*",
113+
"sigstore_protobuf_specs.*",
114+
"pyspx.*",
115+
"azure.*",
116+
"boto3.*",
117+
"botocore.*",
118+
"hvac.*",
119+
]
120+
ignore_missing_imports = "True"
121+
122+
[[tool.mypy.overrides]]
123+
module = [
124+
"securesystemslib._gpg.*",
125+
"securesystemslib._vendor.*",
126+
"securesystemslib.hash",
127+
]
128+
follow_imports = "skip"

securesystemslib/py.typed

Whitespace-only changes.

securesystemslib/signer/_hsm_signer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
_PYKCS11LIB = None
6565

6666

67-
def PYKCS11LIB(): # noqa: N802
67+
def PYKCS11LIB(): # type: ignore[no-untyped-def] # noqa: N802
6868
"""Pseudo-singleton to load shared library using PYKCS11LIB envvar only once."""
6969
global _PYKCS11LIB # noqa: PLW0603
7070
if _PYKCS11LIB is None:

securesystemslib/signer/_key.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
SECP256R1,
2727
SECP384R1,
2828
SECP521R1,
29+
EllipticCurve,
2930
EllipticCurvePublicKey,
3031
)
3132
from cryptography.hazmat.primitives.asymmetric.ed25519 import (
@@ -346,11 +347,13 @@ def _verify_ed25519_fallback(self, signature: bytes, data: bytes) -> None:
346347
def _verify(self, signature: bytes, data: bytes) -> None:
347348
"""Helper to verify signature using pyca/cryptography (default)."""
348349

349-
def _validate_type(key, type_):
350+
def _validate_type(key: object, type_: type) -> None:
350351
if not isinstance(key, type_):
351352
raise ValueError(f"bad key {key} for {self.scheme}")
352353

353-
def _validate_curve(key, curve):
354+
def _validate_curve(
355+
key: EllipticCurvePublicKey, curve: type[EllipticCurve]
356+
) -> None:
354357
if not isinstance(key.curve, curve):
355358
raise ValueError(f"bad curve {key.curve} for {self.scheme}")
356359

securesystemslib/signer/_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from securesystemslib.formats import encode_canonical
1010

1111

12-
def compute_default_keyid(keytype: str, scheme, keyval: dict[str, Any]) -> str:
12+
def compute_default_keyid(keytype: str, scheme: str, keyval: dict[str, Any]) -> str:
1313
"""Return sha256 hexdigest of the canonical json of the key."""
1414
data: str | None = encode_canonical(
1515
{

securesystemslib/storage.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from abc import ABCMeta, abstractmethod
2626
from collections.abc import Iterator
2727
from contextlib import contextmanager
28-
from typing import IO, BinaryIO
28+
from typing import IO, Any, BinaryIO
2929

3030
from securesystemslib import exceptions
3131

@@ -189,7 +189,7 @@ class FilesystemBackend(StorageBackendInterface):
189189
# objects.
190190
_instance = None
191191

192-
def __new__(cls, *args, **kwargs):
192+
def __new__(cls, *args: Any, **kwargs: Any) -> FilesystemBackend:
193193
if cls._instance is None:
194194
cls._instance = object.__new__(cls, *args, **kwargs)
195195
return cls._instance

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ commands =
6969
ruff format --diff {[testenv:lint]lint_dirs}
7070
ruff check {[testenv:lint]lint_dirs}
7171

72-
mypy {[testenv:lint]lint_dirs}
72+
mypy securesystemslib
7373
zizmor --persona=pedantic -q .
7474

7575
[testenv:fix]

0 commit comments

Comments
 (0)